home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 1 / CU Amiga Magazine CD-ROM Special Edition (1995)(EMAP Images)(GB)[Issue 1995-11].iso / Aminet / comm / tcp / AmiTCPtxt_20.lha / doc / systext.txt < prev    next >
Text File  |  1993-08-13  |  475KB  |  13,719 lines

  1.  
  2.  
  3.  
  4.  
  5.                         AmiTCP/IP
  6.  
  7.  
  8.  
  9.                      System  Manual
  10.  
  11.  
  12.                              Revision: 2.4
  13.  
  14.  
  15.  
  16.                           amitcp-group@hut.fi
  17.  
  18.  
  19.  
  20. Tomi Ollila      Pekka Pessi      Markus Peuhkuri      Jarno  Rajahalme
  21.  
  22.  
  23.  
  24.                            August 13, 1993
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32. Foreword
  33.  
  34.  
  35.  
  36. What  Is  AmiTCP/IP
  37.  
  38.  
  39. The Programming Project is a software engineering course here at Helsinki
  40. University of Technology.  A group of 3---4 students designs, implements
  41. and tests a complete working software system during this course.
  42.    Our purpose was to provide a free TCP/IP implementation for all Amiga
  43. users.  Lack of a standard networking interface was anirritating
  44. shortcoming of the Amiga systems.
  45.    AmiTCP/IPis a protocol stack implementing basic Internet protocols on
  46. top of any SANA-II network device driver(for Ethernet, SLIP, etc.).  The
  47. protocol stack offers the standard Berkeley Socket application program
  48. interface (API) to the TCP/IP protocolsimplemented as an Amiga shared
  49. library.
  50.    Using AmiTCP/IP and appropriate client program you can connect to any
  51. services available on your TCP/IP network.
  52.  
  53.  
  54.  
  55. How  Is  This  Achieved
  56.  
  57.  
  58. At first we planned to write the whole protocol stack from scratch.
  59. After examining standards about TCP/IP and bibliography about its
  60. implementations we become aware of the possibility of using the BSD NET/2
  61. code as a base of our work.  We discussed about the idea and found good
  62. reasons why the BSD code should be used.  Eventually wedecided to take
  63. that path with the project.
  64.    AmiTCP/IPis built around BSD NET/2 networking code.  Because the
  65. networking part of the BSD UNIX kernel is rather isolated, only a few
  66. kernel routines had to be rewritten to suit the architecture of the
  67. AmiTCP/IP.
  68.    SANA-II and shared library interfaces were added to the bottom and top
  69. of the modified NET/2 code, respectively.
  70.  
  71.  
  72.  
  73. Why Is the BSD Code Used
  74.  
  75.  
  76. Here are some of the pros of the decision:
  77.  
  78.  
  79.    fflWe don't need to reimplement the most complex part (and all the bugs)
  80.     of the system.
  81.  
  82.  
  83.  
  84.                                        i
  85.  
  86.  
  87.  
  88.  
  89.  
  90.    fflWe noticed that the BSD kernel support for the networking part is
  91.     easy enough to implement using powerful Amiga features.
  92.  
  93.    fflWhen improvements are done to the NET/2 code, we can improve
  94.     AmiTCP/IP by simply replacing the old code with the changed one.
  95.  
  96.    fflWe are offering the socket application interface.  It is the most
  97.     used interface in networking programs with TCP/IP. Using the NET/2
  98.     code makes it easy to implement the BSD socket related function call
  99.     interface as our API.
  100.  
  101.    fflWe can easily port crucial network utilities from the BSD.
  102.  
  103.  
  104.  
  105. About SANA-II
  106.  
  107. Bottom level interface to the SANA-II device drivers was an obvious
  108. choice.  SANA-II is the Amiga standard interface for network devices, and
  109. most manufacturers are shipping SANA-IIcompatible device drivers for
  110. their hardware.  There are also some freely distributable SANA-II drivers
  111. e.g.  for the standard serial interface.
  112.    Althoughthere may be few problems with different network types the
  113. AmiTCP/IP should be able to use all SANA-II device drivers which support
  114. IP.
  115.  
  116.  
  117.  
  118. Release 2.0
  119.  
  120. This release of AmiTCP/IP includes onlythe protocol stack (AmiTCP),
  121. test programs, basic network utilities and example client and servers.
  122. The distribution still lacks most basicclient and server programs.
  123.    The second release of the AmiTCP/IP contains some improvements and bug
  124. fixes over the first release.  It is incompatible withprevious version
  125. in binary level, however.  Old applications and the newlibrary DO NOT
  126. work together.  If you have an application compiled with previous version
  127. of AmiTCP/IP, it MUST be recompiled.  We hope that thisis the only
  128. downward incompatible release.
  129.    The AmiTCP/IP Group requests all users of the AmiTCP/IP to return any
  130. new applications or improved versions tothe AmiTCP/IP Group,
  131. <amitcp-group@hut.fi>, and grant it theright to redistribute them.
  132.  
  133.  
  134.  
  135.                                       ii
  136.  
  137.  
  138.  
  139.  
  140.  
  141. Acknowledgments
  142.  
  143.  
  144. We would like to thank
  145.  
  146.    fflComputer Systems Research Group from University of California,
  147.     Berkeley, for developing BSD Unix system.
  148.  
  149.    fflCarnegie Mellon University for Mach bsdss port of BSD Net/2.
  150.  
  151.    fflAntti Louko <alo@hut.fi>, our project supervisor, from the Computing
  152.     Centre of the Helsinki University of Technology.
  153.  
  154.    fflJukka Partanen <jtp@cs.hut.fi> for providing the GNU CC
  155.     cross-compiling environment for the Amiga in the HP 9000/700
  156.     workstations.
  157.  
  158.    fflTimo Rossi <trossi@jyu.fi> for providing the SANA-II drivers for
  159.     Western Digital Ethernet cards used in testing.
  160.  
  161.    Further on, Jarno and Markus would like to thank their wives Maarit and
  162. Katri for forgiving those late nights (or early mornings) that we spent
  163. with this project.
  164.  
  165.  
  166.  
  167.                                       iii
  168.  
  169.  
  170.  
  171.  
  172.  
  173.    AmiTCP/IPcontains material derived from BSD net/2 release.  The
  174. following acknowledgement should be included in all AmiTCP/IP
  175. distributions:
  176.  
  177.  
  178.    Copyright cfl1982, 1986, 1988, 1990 Regents of the University of
  179. California.  All rights reserved.
  180.    Redistribution and use in source and binary forms, with or without
  181. modification, are permitted provided that the following conditions are
  182. met:
  183.  
  184.  
  185.  1. Redistributions of source code must retain the above copyright
  186.     notice, this list of conditions and the following disclaimer.
  187.  
  188.  2. Redistributions in binary form must reproduce the above copyright
  189.     notice, this list of conditions and the following disclaimer in the
  190.     documentation and/or other materials provided with the distribution.
  191.  
  192.  3. All advertising materials mentioning features or use of this software
  193.     must display the following acknowledgment:  This product includes
  194.     software developed by the University of California, Berkeley and its
  195.     contributors.
  196.  
  197.  4. Neither the name of the University nor the names of its contributors
  198.     may be used to endorse or promote products derived from this software
  199.     without specific prior written permission.
  200.  
  201.  
  202.    THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  203. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  204. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  205. PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
  206. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  207. CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  208. SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  209. INTERRUPTION) HOWEVER CAUSED AND ON ANYTHEORY OF LIABILITY, WHETHER IN
  210. CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  211. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  212. THE POSSIBILITY OF SUCH DAMAGE.
  213.  
  214.  
  215.  
  216.                                       iv
  217.  
  218.  
  219.  
  220.  
  221.  
  222.    Some codeof the AmiTCP/IP originates from the BSDSS 4 by CMU, which
  223. is hereby acknowledged:
  224.  
  225.  
  226. Mach Operating System.
  227. Copyright cfl1992 Carnegie Mellon University.
  228. All Rights Reserved.
  229.  
  230.  
  231. Permission to use, copy, modify and distribute this software and its
  232. documentation is hereby granted, provided that both the copyright notice
  233. and this permission notice appear in allcopies of the software,
  234. derivative works or modified versions, and any portions thereof, and that
  235. both notices appear in supporting documentation.
  236.  
  237.  
  238. CARNEGIE MELLON ALLOWS FREE USE OF THISSOFTWARE IN ITS "AS IS"
  239. CONDITION. CARNEGIE MELLON DISCLAIMS ANYLIABILITY OF ANY KIND FOR ANY
  240. DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  241.  
  242.  
  243. Carnegie Mellon requests users of this software to return to
  244.  
  245.  
  246. Software Distribution Coordinator
  247. School of Computer Science
  248. Carnegie Mellon University
  249. Pittsburgh PA 15213-3890
  250.  
  251.  
  252. or Software.Distribution@CS.CMU.EDU
  253.  
  254.  
  255. any improvements or extensions that theymake and grant Carnegie Mellon
  256. the rights to redistribute these changes.
  257.  
  258.  
  259.  
  260.                                        v
  261.  
  262.  
  263.  
  264.  
  265.  
  266. vi
  267.  
  268.  
  269.  
  270.  
  271.  
  272. About  This  Manual
  273.  
  274.  
  275. How This Manual Is Organized
  276.  
  277. We have tried to organize this manual sothat you are not forced to read
  278. material that you are not interested in.  In order to achieve this we
  279. have divided the text into following chapters:
  280.  
  281.  
  282.  1. User's Manual gives you basic information about using the AmiTCP/IP
  283.     system.  Descriptions about our debugging tools qwriter and
  284.     agnet.device is also included here.
  285.  
  286.  
  287.  2. Interfaces describes briefly all external interfaces of the
  288.     AmiTCP/IP.
  289.  
  290.  
  291.  3. Programmer's Manual gives you the needed information to use
  292.     AmiTCP/IP to make your own network-aware programs.
  293.  
  294.  
  295.  4. Internal Description gives you information about the internal
  296.     structure of the AmiTCP/IP-system.  This is meant for all of you who
  297.     are interested in the internal design of the AmiTCP/IP.
  298.  
  299.  
  300.  5. Implementation Notes is written for those of you who are going to
  301.     maintain AmiTCP/IP or plan to develop it further.
  302.  
  303.  
  304.    There arealso two appendices, the user and programmer reference
  305. guides.  These appendices are in the AutoDoc format andthey are also
  306. available in machine readable form.
  307.    If you have trouble understanding the jargon1  or TLAs1  refer to the
  308. glossary at the end of this manual.
  309.  
  310.  
  311.  
  312. Typographical Conventions
  313.  
  314. To help you to understand the text in this manual, following typefaces
  315. and punctuation are used:
  316.  
  317.  
  318.      Roman   is the basic typeface used throughout the text.
  319.  
  320.  
  321.    Slanted   is used in text which we want youto take special attention
  322.              on.
  323.  
  324.  
  325.    Italics   is used to introduce new terms and concepts which will be
  326.              explained shortly.  Italics is also used to refer to the
  327.              names of the publications and tothe sections of this manual.
  328.  
  329.  
  330. Typed Text   is used for literal program codeand items specific to the
  331.              implementation, such as functionnames, identifiers and C
  332.              language keywords.
  333.  
  334.  
  335.       Bold   text is used to refer to specificfiles and command names
  336.              used by AmiTCP/IP.
  337. ________________________________
  338.    1See glossary.
  339.  
  340.  
  341.  
  342.                                       vii
  343.  
  344.  
  345.  
  346.  
  347.  
  348. Syntax Conventions
  349.  
  350. There are few syntactic conventions usedin this manual:
  351.  
  352.  
  353.        [:::] Square brackets are used for bibliographical references, list
  354.              of which can be found from the end of this manual.
  355.  
  356.  hargumenti  User supplied required argumentsare printed between angle
  357.              brackets.
  358.  
  359. [argument]   User supplied optional argumentsare printed between square
  360.              brackets.
  361.  
  362. function()   C function names are followed bya pair of parenthesis.  The
  363.              preprocessor macros---as opposedto the genuine
  364.              functions---are in upper case.
  365.  
  366.  
  367.  
  368.                                      viii
  369.  
  370.  
  371.  
  372.  
  373.  
  374. GNU  GENERAL  PUBLIC  LICENSE
  375.  
  376.  
  377.                              Version 2, June 1991
  378.  
  379. Copyright (C) 1989, 1991 Free Software Foundation, Inc.  675 Mass Ave,
  380. Cambridge, MA 02139, USA
  381.  
  382.    Everyoneis permitted to copy and distribute verbatim copies of this
  383. license document, but changing it is notallowed.
  384.  
  385.  
  386.  
  387. Preamble
  388.  
  389.  
  390. The licenses for most software are designed to take away your freedom to
  391. share and change it.  By contrast, the GNU General Public License is
  392. intended to guarantee your freedom to share and change free software---to
  393. make sure the software is free for all its users.   This General Public
  394. License applies to most of the Free Software Foundation's software and to
  395. any other program whose authors commit to using it.   (Some other Free
  396. Software Foundation software is coveredby the GNU Library General Public
  397. License instead.)  You can apply it to your programs, too.
  398.  
  399.    When we speak of free software, we are referring to freedom, not price.
  400. Our General Public Licenses are designedto make sure that you have the
  401. freedom to distribute copies of free software (and charge for this
  402. service if you wish), that you receive source code or can get it if you
  403. want it, that you can change the software or use pieces of it in new free
  404. programs; and that you know you can do these things.
  405.  
  406.    To protect your rights, we need to make restrictions that forbid anyone
  407. to deny you these rights or to ask you to surrender the rights.  These
  408. restrictions translate to certain responsibilities for you if you
  409. distribute copies of the software, or ifyou modify it.
  410.  
  411.    For example, if you distribute copies of such a program, whether gratis
  412. or for a fee, you must give the recipients all the rights that you have.
  413. You must make sure that they, too, receive or can get the source code.
  414. And you must show them these terms so they know their rights.
  415.  
  416.    We protect your rights with two steps:  (1) copyright the software, and
  417. (2) offer you this license which gives you legal permission to copy,
  418. distribute and/or modify the software.
  419.  
  420.    Also, foreach author's protection and ours, we want to make certain
  421. that everyone understands that there isno warranty for this free
  422. software.  If the software is modified by someone elseand passed on, we
  423. want its recipients to know that what they have is not the original, so
  424. that any problems introduced by others will not reflect on the original
  425. authors' reputations.
  426.  
  427.    Finally,any free program is threatened constantly by software patents.
  428. We wish to avoid the danger that redistributors of a free program will
  429. individually obtain patent licenses, ineffect making the program
  430. proprietary.  To prevent this, we have made it clear that any patent must
  431. be licensed for everyone's free use or not licensed at all.
  432.  
  433.    The precise terms and conditions for copying, distribution and
  434. modification follow.
  435.  
  436.  
  437.  
  438.                                       ix
  439.  
  440.  
  441.  
  442.  
  443.  
  444. TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
  445.  
  446.  1. This License applies to any program or other work which contains a
  447.     notice placed by the copyright holder saying it may be distributed
  448.     under the terms of this General Public License.  The ``Program'',
  449.     below, refers to any such program or work, and a ``work based on the
  450.     Program'' means either the Program or any derivative work under
  451.     copyright law:  that is to say, a work containing the Program or a
  452.     portion of it, either verbatim or with modifications and/or
  453.     translated into another language.  (Hereinafter, translation is
  454.     included without limitation in the term ``modification''.)  Each
  455.     licensee is addressed as ``you''.
  456.  
  457.     Activities other than copying, distribution and modification are not
  458.     covered by this License; they are outside its scope.  The act of
  459.     running the Program is not restricted, and the output from the
  460.     Program is covered only if its contents constitute a work based on
  461.     the Program (independent of having been made by running the Program).
  462.     Whether that is true depends on what the Program does.
  463.  
  464.  2. You may copy and distribute verbatim copies of the Program's source
  465.     code as you receive it, in any medium, provided that you
  466.     conspicuously and appropriately publish on each copy an appropriate
  467.     copyright notice and disclaimer of warranty; keep intact all the
  468.     notices that refer to this License and to the absence of any
  469.     warranty; and give any other recipients of the Program a copy of this
  470.     License along with the Program.
  471.  
  472.     You may charge a fee for the physical act of transferring a copy, and
  473.     you may at your option offer warranty protection in exchange for a
  474.     fee.
  475.  
  476.  3. You may modify your copy or copies of the Program or any portion of
  477.     it, thus forming a work based on the Program, and copy and distribute
  478.     such modifications or work under the terms of Section 1 above,
  479.     provided that you also meet all of these conditions:
  480.  
  481.     (a) You must cause the modified files to carry prominent notices
  482.         stating that you changed the files and the date of anychange.
  483.  
  484.     (b) You must cause any work that you distribute or publish,that in
  485.         whole or in part contains or is derived from the Program or any
  486.         part thereof, to be licensed as a whole at no charge toall third
  487.         parties under the terms of this License.
  488.  
  489.     (c) if the modified program normally reads commands interactively
  490.         when run, you must cause it, when started running for such
  491.         interactive use in the most ordinary way, to print or display an
  492.         announcement including an appropriate copyright noticeand a
  493.         notice that there is no warranty (or else, saying thatyou
  494.         provide a warranty) and that users may redistribute theprogram
  495.         under these conditions, and telling the user how to view a copy
  496.         of this License.  (Exception:  if the Program itself is
  497.         interactive but does not normally print such an announcement,
  498.         your work based on the Program is not required to printan
  499.         announcement.)
  500.  
  501.  
  502.  
  503.                                        x
  504.  
  505.  
  506.  
  507.  
  508.  
  509.    These requirements apply to the modified work as a whole.  If
  510.    identifiable sections of that work are not derived from the Program,
  511.    and can be reasonably considered independent and separate works in
  512.    themselves, then this License, and its terms, do not apply to those
  513.    sections when you distribute them as separate works.  But when you
  514.    distribute the same sections as part of a whole which is a work based
  515.    on the Program, the distribution of the whole must be on the terms of
  516.    this License, whose permissions for other licensees extend to the
  517.    entire whole, and thus to each and every part regardless of who wrote
  518.    it.
  519.  
  520.    Thus, it is not the intent of this section to claim rights or contest
  521.    your rights to work written entirely by you; rather, the intent is to
  522.    exercise the right to control the distribution of derivative or
  523.    collective works based on the Program.
  524.  
  525.    In addition, mere aggregation of another work not based on the
  526.    Program with the Program (or with a work based on the Program) on a
  527.    volume of a storage or distribution medium does not bring the other
  528.    work under the scope of this License.
  529.  
  530.  
  531. 4. You may copy and distribute the Program (or a work based on it, under
  532.    Section 2) in object code or executable form under the terms of
  533.    Sections 1 and 2 above provided that you also do one of the
  534.    following:
  535.  
  536.  
  537.    (a) Accompany it with the complete corresponding machine-readable
  538.        source code, which must be distributed under the termsof
  539.        Sections 1 and 2 above on a medium customarily used forsoftware
  540.        interchange; or,
  541.  
  542.    (b) Accompany it with a written offer, valid for at least three
  543.        years, to give any third party, for a charge no more than your
  544.        cost of physically performing source distribution, a complete
  545.        machine-readable copy of the corresponding source code,to be
  546.        distributed under the terms of Sections 1 and 2 above on a medium
  547.        customarily used for software interchange; or,
  548.  
  549.    (c) Accompany it with the information you received as to the offer to
  550.        distribute corresponding source code.  (This alternative is
  551.        allowed only for noncommercial distribution and only ifyou
  552.        received the program in object code or executable formwith such
  553.        an offer, in accord with Subsection b above.)
  554.  
  555.  
  556.    The source code for a work means the preferred form of the work for
  557.    making modifications to it.  For an executable work, complete source
  558.    code means all the source code for all modules it contains, plus any
  559.    associated interface definition files, plus the scripts used to
  560.    control compilation and installation of the executable.  However, as
  561.    a special exception, the source code distributed need not include
  562.    anything that is normally distributed (in either source or binary
  563.    form) with the major components (compiler, kernel, and so on) of the
  564.    operating system on which the executable runs, unless that component
  565.    itself accompanies the executable.
  566.  
  567.  
  568.  
  569.                                      xi
  570.  
  571.  
  572.  
  573.  
  574.  
  575.    If distribution of executable or object code is made by offering
  576.    access to copy from a designated place, then offering equivalent
  577.    access to copy the source code from the same place counts as
  578.    distribution of the source code, even though third parties are not
  579.    compelled to copy the source along with the object code.
  580.  
  581. 5. You may not copy, modify, sublicense, or distribute the Program
  582.    except as expressly provided under this License.  Any attempt
  583.    otherwise to copy, modify, sublicense or distribute the Program is
  584.    void, and will automatically terminate your rights under this
  585.    License.  However, parties who have received copies, or rights, from
  586.    you under this License will not have their licenses terminated so
  587.    long as such parties remain in full compliance.
  588.  
  589. 6. You are not required to accept this License, since you have not
  590.    signed it.  However, nothing else grants you permission to modify or
  591.    distribute the Program or its derivative works.  These actions are
  592.    prohibited by law if you do not accept this License.  Therefore, by
  593.    modifying or distributing the Program (or any work based on the
  594.    Program), you indicate your acceptance of this License to do so, and
  595.    all its terms and conditions for copying, distributing or modifying
  596.    the Program or works based on it.
  597.  
  598. 7. Each time you redistribute the Program (or any work based on the
  599.    Program), the recipient automatically receives a license from the
  600.    original licensor to copy, distribute or modify the Program subject
  601.    to these terms and conditions.  You may not impose any further
  602.    restrictions on the recipients' exercise of the rights granted
  603.    herein.  You are not responsible for enforcing compliance by third
  604.    parties to this License.
  605.  
  606. 8. If, as a consequence of a court judgment or allegation of patent
  607.    infringement or for any other reason (not limited to patent issues),
  608.    conditions are imposed on you (whether by court order, agreement or
  609.    otherwise) that contradict the conditions of this License, they do
  610.    not excuse you from the conditions of this License.  If you cannot
  611.    distribute so as to satisfy simultaneously your obligations under
  612.    this License and any other pertinent obligations, then as a
  613.    consequence you may not distribute the Program at all.  For example,
  614.    if a patent license would not permit royalty-free redistribution of
  615.    the Program by all those who receive copies directly or indirectly
  616.    through you, then the only way you could satisfy both it and this License
  617.    would be to refrain entirely from distribution of the Program.
  618.  
  619.    If any portion of this section is held invalid or unenforceable under
  620.    any particular circumstance, the balance of the section is intended
  621.    to apply and the section as a whole is intended to apply in other
  622.    circumstances.
  623.  
  624.    It is not the purpose of this section to induce you to infringe any
  625.    patents or other property right claims or to contest validity of any
  626.    such claims; this section has the sole purpose of protecting the
  627.    integrity of the free software distribution system, which is
  628.    implemented by public license practices.  Many people have made
  629.  
  630.  
  631.  
  632.                                      xii
  633.  
  634.  
  635.  
  636.  
  637.  
  638.     generous contributions to the wide range of software distributed
  639.     through that system in reliance on consistent application of that
  640.     system; it is up to the author/donor to decide if he or she is
  641.     willing to distribute software through any other system and a
  642.     licensee cannot impose that choice.
  643.  
  644.     This section is intended to make thoroughly clear what is believed to
  645.     be a consequence of the rest of this License.
  646.  
  647.  9. If the distribution and/or use of the Program is restricted in
  648.     certain countries either by patents or by copyrighted interfaces, the
  649.     original copyright holder who places the Program under this License
  650.     may add an explicit geographical distribution limitation excluding
  651.     those countries, so that distribution is permitted only in or among
  652.     countries not thus excluded.  In such case, this License incorporates
  653.     the limitation as if written in the body of this License.
  654.  
  655. 10. The Free Software Foundation may publish revised and/or new versions
  656.     of the General Public License from time to time.  Such new versions
  657.     will be similar in spirit to the present version, but may differ in
  658.     detail to address new problems or concerns.
  659.  
  660.     Each version is given a distinguishing version number.  If the
  661.     Program specifies a version number of this License which applies to
  662.     it and ``any later version'', you have the option of following the
  663.     terms and conditions either of that version or of any later version
  664.     published by the Free Software Foundation.  If the Program does not
  665.     specify a version number of this License, you may choose any version
  666.     ever published by the Free Software Foundation.
  667.  
  668. 11. If you wish to incorporate parts of the Program into other free
  669.     programs whose distribution conditions are different, write to the
  670.     author to ask for permission.  For software which is copyrighted by
  671.     the Free Software Foundation, write to the Free Software Foundation;
  672.     we sometimes make exceptions for this.  Our decision will be guided
  673.     by the two goals of preserving the free status of all derivatives of
  674.     our free software and of promoting the sharing and reuse of software
  675.     generally.
  676.  
  677.  
  678.  
  679.                                NO  WARRANTY
  680.  
  681. 12. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
  682.     FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT
  683.     WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER
  684.     PARTIES PROVIDE THE PROGRAM ``AS IS'' WITHOUT WARRANTY OF ANY KIND,
  685.     EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
  686.     IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  687.     PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
  688.     PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME
  689.     THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
  690.  
  691. 13. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
  692.     WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
  693.     REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR
  694.  
  695.  
  696.  
  697.                                      xiii
  698.  
  699.  
  700.  
  701.  
  702.  
  703.     DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL
  704.     DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM
  705.     (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED
  706.     INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE
  707.     OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH
  708.     HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
  709.     DAMAGES.
  710.  
  711.  
  712.  
  713. END OF TERMS AND CONDITIONS
  714.  
  715.  
  716.  
  717.                                       xiv
  718.  
  719.  
  720.  
  721.  
  722.  
  723. Contents
  724.  
  725.  
  726.  
  727. 1  User's Manual                                                             1
  728.    1.1  Installation : : : : : : : : : : : : : : : : : : :: : : : : : : : : : :*
  729.  * : : : : : : :   1
  730.         1.1.1  Using the SLIP Drivers: : : : : : : : : : : : : : : : : : : : : *
  731.  *: : : :   2
  732.                Common Problems with the SLIP Driver And AmiTCP/IP : : : :   2
  733.    1.2  Configuration : : : : : : : : : : : : : : : : : : : : : : : : : : : : :*
  734.  * : : : :: : :    3
  735.         1.2.1  Options : : : : : : : : : : : : : :: : : : : : : : : : : : : : :*
  736.  * : : : : : : :   4
  737.         1.2.2  Network Database : : : : : : : : : : : : : : : : : : : : : : : :*
  738.  * : : : : :   4
  739.    1.3  Internet Addressing : : : : : :: : : : : : : : : : : : : : : : : : : : *
  740.  *: : : : : :   4
  741.         1.3.1  Internet Dot Notation : : : : : : : : : : : : : : : : : : : : : *
  742.  *: : : :   5
  743.         1.3.2  Nets and Routing : : : : : : : : : : : : : : : : : : : : : : : :*
  744.  * : :: : :    5
  745.         1.3.3  Subnets : : : : : : : : : : : : : :: : : : : : : : : : : : : : :*
  746.  * : : : : : : :   6
  747.         1.3.4  Broadcast Addresses : : : : : : : : : : : : : :: : : : : : : : :*
  748.  * : : : :   6
  749.    1.4  Utilities : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : :*
  750.  * : : : :: : : :   7
  751.         1.4.1  arp : : : : : : : : : : : : : : : :: : : : : : : : : : : : : : :*
  752.  * : : : : : : : :   7
  753.         1.4.2  ifconfig : : : : : : : : : : : : : : : : : : : : : : : : : : : :*
  754.  *: : : : : : :   7
  755.         1.4.3  letnet: : : : : : : : : : : : : : : : : : : : : : : : : : : : : *
  756.  *: : : : : : : :   8
  757.         1.4.4  netstat : : : : : : : : : : : : : :: : : : : : : : : : : : : : :*
  758.  * : : : : : : :   8
  759.         1.4.5  NapsaTerm  : :: : : : : : : : : : : : : : : : : : : : : : : : : *
  760.  *: : : : : : :   8
  761.         1.4.6  offline : : : : : : : : : : : : : :: : : : : : : : : : : : : : :*
  762.  * : : : : : : :   9
  763.         1.4.7  online: : : : : : : : : : : : : : : : : : : : : : : : : : : : : *
  764.  *: : : : : : : :   9
  765.         1.4.8  route  : : : :: : : : : : : : : : : : : : : : : : : : : : : : : *
  766.  *: : : : : : : :   9
  767.    1.5  Errors and Logging  : : : : : :: : : : : : : : : : : : : : : : : : : : *
  768.  *: : : : : :   9
  769.    1.6  Troubleshooting : : : :: : : : : : : : : : : : : : : : : : : : : : : : *
  770.  *: : : : : : :  10
  771.    1.7  Testing Utilities : : : : : : : : : : : : : : : : : : : : : : : : : : :*
  772.  * : : : : : :  10
  773.         1.7.1  Agnet  : : : :: : : : : : : : : : : : : : : : : : : : : : : : : *
  774.  *: : : : : : : :  10
  775.                ARexx Port for agnet.device : : : : : : : :: : : : : : : : : : :*
  776.  * : :  11
  777.         1.7.2  Qwriter : : : : : : : : : : : : : :: : : : : : : : : : : : : : :*
  778.  * : : : : : : :  13
  779.                Command Line Options : : : : : : : : : : : : : : : : : : : : : :*
  780.  * : :: :  13
  781.  
  782.  
  783. 2  Interfaces                                                               15
  784.    2.1  AmiTCP/IP Processes : : : : : :: : : : : : : : : : : : : : : : : : : : *
  785.  *: : : : : :  15
  786.    2.2  Application Interface : : : : : : : : : : : : : : : : : : : : : : : : :*
  787.  * : : : : :  16
  788.    2.3  SANA-II Interface : : : : : : : : : : : : : : : : : : : : : : : : : : :*
  789.  * : : : : : :  16
  790.         2.3.1  Interface ioctls : : : : : : : : : : : : : : : : : : : : : : : :*
  791.  * : : : : :  17
  792.    2.4  Configuration Files : : : : : :: : : : : : : : : : : : : : : : : : : : *
  793.  *: : : : : :  17
  794.    2.5  ARexx Interface : : : : : : :: : : : : : : : : : : : : : : : : : : : : *
  795.  *: : : : : : :  17
  796.         2.5.1  Commands : : : : : : : : : : : : : : : : : : : : : : : : : : : :*
  797.  *: : : : : : :  18
  798.         2.5.2  Variables  : :: : : : : : : : : : : : : : : : : : : : : : : : : *
  799.  *: : : : : : :  19
  800.                Boolean variables  : : :: : : : : : : : : : : : : : : : : : : : *
  801.  *: : : : :  23
  802.  
  803.  
  804.  
  805.                                       xv
  806.  
  807.  
  808.  
  809.  
  810.  
  811.                CONNECTIONS output format : : : : : : : : : : : : : : : : : : : *
  812.  *: : :  24
  813.                ICMPHIST output format: : : : : : : : : : : : : : : : : : : : : *
  814.  *: : : :  24
  815.  
  816.  
  817. 3  Programmer's Manual                                                     27
  818.    3.1  Socket Concepts : : : : : : :: : : : : : : : : : : : : : : : : : : : : *
  819.  *: : : : : : :  27
  820.         3.1.1  Socket Types : : : : : : : : : : : : : : : : : : : : : : : : : :*
  821.  * : : : : ::  27
  822.         3.1.2  Using The Socket Library : : : : : : : : : : : : : : : : : : : :*
  823.  * : : :  28
  824.         3.1.3  Compiling and Linking The Applications: : : : : : : : : : : : : *
  825.  * 30
  826.                The NETINCLUDE Header Files : : : : : : : :: : : : : : : : : : :*
  827.  * : :  30
  828.                Linking With net.lib : : : : : : : : : : : : : : : : : : : : : :*
  829.  * : :: :  32
  830.         3.1.4  Socket Creation : : : : : : : : : : : : : : :: : : : : : : : : :*
  831.  * : : : : :  32
  832.         3.1.5  Binding Local Names : : : : : : : : : :: : : : : : : : : : : : :*
  833.  * : : : :  33
  834.         3.1.6  Connection Establishment : : : : : : : : : : : : : : : : : : : :*
  835.  * : : :  34
  836.         3.1.7  Data Transfer  : : : : :: : : : : : : : : : : : : : : : : : : : *
  837.  *: : : : : :  36
  838.         3.1.8  Discarding Sockets: : : : : : : : : : : : : : : : : : : : : : : *
  839.  *: : : : :  36
  840.         3.1.9  Connectionless Sockets: : : : : : : : : : : : : : : : : : : : : *
  841.  *: : : :  37
  842.         3.1.10 Input/Output Multiplexing  :: : : : : : : : : : : : : : : : : : *
  843.  *: : :  38
  844.    3.2  Network Library Routines : : : : : : : : : : : : : : :: : : : : : : : :*
  845.  * : : : :  40
  846.         3.2.1  Host Names : :: : : : : : : : : : : : : : : : : : : : : : : : : *
  847.  *: : : : : : :  40
  848.         3.2.2  Network Names  : : : : :: : : : : : : : : : : : : : : : : : : : *
  849.  *: : : : : :  41
  850.         3.2.3  Protocol Names :: : : : : : : : : : : : : : : : : : : : : : : : *
  851.  *: : : : : :  41
  852.         3.2.4  Service Names  : : : : :: : : : : : : : : : : : : : : : : : : : *
  853.  *: : : : : :  42
  854.         3.2.5  Miscellaneous  :: : : : : : : : : : : : : : : : : : : : : : : : *
  855.  *: : : : : :  42
  856.                Remote Login Client Code : : : : : : : : : : : : : : : : : : : :*
  857.  * : : :  42
  858.    3.3  Client/Server Model : : : : : :: : : : : : : : : : : : : : : : : : : : *
  859.  *: : : : : :  44
  860.         3.3.1  Servers : : : : : : : : : : : : : :: : : : : : : : : : : : : : :*
  861.  * : : : : : : :  45
  862.         3.3.2  Clients : : : : : : : : : : : : : :: : : : : : : : : : : : : : :*
  863.  * : : : : : : :  47
  864.         3.3.3  Connectionless Servers: : : : : : : : : : : : : : : : : : : : : *
  865.  *: : : :  48
  866.                Ruptime Output :: : : : : : : : : : : : : : : : : : : : : : : : *
  867.  *: : : : : :  48
  868.    3.4  Advanced Topics : : : : : : :: : : : : : : : : : : : : : : : : : : : : *
  869.  *: : : : : : :  51
  870.         3.4.1  Out Of Band Data : : : : : : : : : : : : : : : : : : : : : : : :*
  871.  * : :: : :  51
  872.         3.4.2  Non-Blocking Sockets : : : : : : : : : : : : : : : : : : : : : :*
  873.  * : : : :  53
  874.         3.4.3  Signal Driven Socket I/O : : : : : : : : : : : : : : : : : : : :*
  875.  * : : :  54
  876.         3.4.4  Selecting Specific Protocols : : : : : : : : : : : : : : : : : :*
  877.  * : :  55
  878.         3.4.5  Address Binding : : : : : : : : : : : : : : :: : : : : : : : : :*
  879.  * : : : : :  55
  880.         3.4.6  Broadcasting And Determining Network Configuration : : : :  58
  881.                AmiTCP/IP specific extensions : : : : : : : : : : : : : : : : : *
  882.  *: :  60
  883.                Extensions to interface ioctls: : : : : : : : : : : : : : : : : *
  884.  *: :  60
  885.         3.4.7  Socket Options :: : : : : : : : : : : : : : : : : : : : : : : : *
  886.  *: : : : : :  61
  887.         3.4.8  Inetd  : : : :: : : : : : : : : : : : : : : : : : : : : : : : : *
  888.  *: : : : : : : :  62
  889.    3.5  Deviation From Berkeley Sockets: : : : : : : : : : : : : : : : : : : : *
  890.  *: : :  63
  891.         3.5.1  Opening and Closing the Shared Library: : : : : : : : : : : : : *
  892.  * 63
  893.         3.5.2  Naming Conventions of the API Functions : : :: : : : : : : : :  *
  894.  *63
  895.         3.5.3  errno  : : : :: : : : : : : : : : : : : : : : : : : : : : : : : *
  896.  *: : : : : : : :  64
  897.         3.5.4  New Field in the sockaddr Structures : : : : : : : : : : : : : :*
  898.  *  64
  899.         3.5.5  Linger Time : : : : : : : : : : : : : : : : :: : : : : : : : : :*
  900.  * : : : : : :  64
  901.         3.5.6  Transferring Sockets from a Task to Another : :: : : : : : :  64
  902.         3.5.7  Ioctl Differences  : : :: : : : : : : : : : : : : : : : : : : : *
  903.  *: : : : :  65
  904.         3.5.8  Signal Handling : : : : : : : : : : : : : : :: : : : : : : : : :*
  905.  * : : : : :  65
  906.         3.5.9  Asynchronous I/O : : : : : : : : : : : : : : : : : : : : : : : :*
  907.  * : : : : :  66
  908.         3.5.10 Constructing an Event Loop: : : : : : : : : : : : : : : : : : : *
  909.  *: : :  66
  910.  
  911.  
  912.  
  913.                                       xvi
  914.  
  915.  
  916.  
  917.  
  918.  
  919.         3.5.11 ''Killing'' the Processes : : : : : : : : : : : : : : : : : : : *
  920.  *: : :  67
  921.         3.5.12 WaitSelect() : : : : : : : : : : : : : : : : : : : : : : : : : :*
  922.  * :: : : : :  67
  923.  
  924.  
  925. 4  Internal Description                                                    69
  926.    4.1  Source File Structure : : : : : : : : : : : : : : : : : : : : : : : : :*
  927.  * : : : : :  69
  928.         4.1.1  System Include Files : : : : : : : : : : : : : : : : : : : : : :*
  929.  * : :: :  69
  930.         4.1.2  Protocol Independent Network Routines : : : : : : : : : : : : : *
  931.  * 70
  932.         4.1.3  Internet Protocol Modules : : : : : : : : : : : : : : : : : : : *
  933.  *: : :  71
  934.         4.1.4  BSD Kernel Service Modules: : : : : : : : : : : : : : : : : : : *
  935.  *: : :  72
  936.         4.1.5  BSD Socket API: : : : : : : : : : : : : : : : : : : : : : : : : *
  937.  *: : : : : :  73
  938.         4.1.6  Miscellaneous Files : : : : : : : : : : : : : :: : : : : : : : :*
  939.  * : : : :  75
  940.    4.2  AmiTCP/IP Initialization : : : : : : : : : : : : : : : : : : :: : : : :*
  941.  * : : : :  75
  942.         4.2.1  init_all() : :: : : : : : : : : : : : : : : : : : : : : : : : : *
  943.  *: : : : : : :  76
  944.         4.2.2  deinit_all() : : : : : : : : : : : : : : : : : : : : : : : : : :*
  945.  * : : : : ::  77
  946.    4.3  The Main Module : : : :: : : : : : : : : : : : : : : : : : : : : : : : *
  947.  *: : : : : : :  77
  948.    4.4  Protocol Entities : : : : : : : : : : : : : : : : : : : : : : : : : : :*
  949.  * : : : : : :  78
  950.    4.5  Memory Management : : : : : : : : : : : : : : : : : : : : : : : : : : :*
  951.  * : : : : : :  79
  952.         4.5.1  Mbuf Functions :: : : : : : : : : : : : : : : : : : : : : : : : *
  953.  *: : : : : :  79
  954.    4.6  Concurrency Control : : : : : :: : : : : : : : : : : : : : : : : : : : *
  955.  *: : : : : :  82
  956.    4.7  Network Device Drivers  : : : : :: : : : : : : : : : : : : : : : : : : *
  957.  *: : : : :  83
  958.         4.7.1  SANA-II Soft Network Interface: : : : : : : : : : : : : : : : : *
  959.  *: :  84
  960.         4.7.2  ARP : : : : : : : : : : : : : : : :: : : : : : : : : : : : : : :*
  961.  * : : : : : : : :  87
  962.    4.8  Logging : : : : : : :: : : : : : : : : : : : : : : : : : : : : : : : : *
  963.  *: : : : : : : : :  88
  964.    4.9  ARexx Interface : : : : : : :: : : : : : : : : : : : : : : : : : : : : *
  965.  *: : : : : : :  89
  966.    4.10 Application Interface Concepts  : :: : : : : : : : : : : : : : : : : : *
  967.  *: : :  90
  968.         4.10.1 SocketBase -- an Extension of the Task Structure  : : : : :  90
  969.         4.10.2 The System Call Semaphore and Task Priorities : : : : : : :  90
  970.    4.11 Configuration Variables : : : : :: : : : : : : : : : : : : : : : : : : *
  971.  *: : : : :  91
  972.    4.12 Network Database : : : : : : : : : : : : : : : : : : : : :: : : : : : :*
  973.  * : : : : : :  92
  974.  
  975.  
  976. 5  Implementation Notes                                                    93
  977.    5.1  Time outs : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : :*
  978.  * : : : : : : ::   93
  979.    5.2  Memory Management : : : : : : : : : : : : : : : : : : : : : : : : : : :*
  980.  * : : : : : :  95
  981.         5.2.1  Mbufs  : : : :: : : : : : : : : : : : : : : : : : : : : : : : : *
  982.  *: : : : : : : :  95
  983.         5.2.2  malloc() & free() : : : : : : : : : : : : : : : : : : : : : : : *
  984.  *: : : : :  95
  985.    5.3  Concurrency Control : : : : : :: : : : : : : : : : : : : : : : : : : : *
  986.  *: : : : : :  96
  987.         5.3.1  Processor Priority Levels : : : : : : : : : : : : : : : : : : : *
  988.  *: : :  96
  989.         5.3.2  Sleeping Facilities : : : : : : : : : : : : : :: : : : : : : : :*
  990.  * : : : :  97
  991.    5.4  Socket Library Creation Procedure : : : : : : : : : : : : : : : : : : :*
  992.  * : :  99
  993.         5.4.1  Master Library Base : : : : : : : : : :: : : : : : : : : : : : :*
  994.  * : : : :  99
  995.         5.4.2  Application Library Bases : : : : : : : : : : : : : : : : : : : *
  996.  *: : :  99
  997.    5.5  The SocketBase Structure : : : : : : : : : : : : : : :: : : : : : : : :*
  998.  * : : : : 100
  999.    5.6  The Application Program Interface : : : : : : : : : : : : : : : : : : :*
  1000.  * : : 102
  1001.         5.6.1  How API Functions Are Ported : : : : : : : : : : : : : : : : : :*
  1002.  * : :102
  1003.         5.6.2  API Functions Which Needed More Modifications : : : : : : : 103
  1004.    5.7  Changes in Functions Below API Level : : : : : : : : : : :: : : : : : :*
  1005.  * : 103
  1006.         5.7.1  Other Changes  : : : : :: : : : : : : : : : : : : : : : : : : : *
  1007.  *: : : : : : 103
  1008.    5.8  Agnet.device : : : : : : : : : : : : : : : : : : :: : : : : : : : : : :*
  1009.  * : : : : : : : 104
  1010.         5.8.1  IO Commands : : : : : : : : : : : : : : : : :: : : : : : : : : :*
  1011.  * : : : : : : 104
  1012.         5.8.2  Initialization Procedure : : : : : : : : : : : : : : : : : : : :*
  1013.  * : : : 106
  1014.         5.8.3  The Device Interface Functions: : : : : : : : : : : : : : : : : *
  1015.  *: : 107
  1016.  
  1017.  
  1018.  
  1019.                                      xvii
  1020.  
  1021.  
  1022.  
  1023.  
  1024.  
  1025.                Opening an Unit : : : : : : : : : : : :: : : : : : : : : : : : :*
  1026.  * : : : : : 107
  1027.                Closing an Unit : : : : : : : : : : : :: : : : : : : : : : : : :*
  1028.  * : : : : : 107
  1029.                Initiating an IO Request : : : : : : : : : : : : : : : : : : : :*
  1030.  * : : :108
  1031.                Aborting an IO Request: : : : : : : : : : : : : : : : : : : : : *
  1032.  *: : : : 108
  1033.                Expunging the Device : : : : : : : : : : : : : : : : : : : : : :*
  1034.  * : :: : 108
  1035.         5.8.4  Packet Delivery : : : : : : : : : : : : : : :: : : : : : : : : :*
  1036.  * : : : : : 109
  1037.         5.8.5  Arexx Interface : : : : : : : : : : : : : : :: : : : : : : : : :*
  1038.  * : : : : : 109
  1039.  
  1040.  
  1041. A  Autodocs for Network Applications and Utilities                      111
  1042.    A.1  Network Utilities : : : : : : : : : : : : : : : : : : : : : : : : : : :*
  1043.  * : : : : : : 112
  1044.         A.1.1  arp : : : : : : : : : : : : : : : :: : : : : : : : : : : : : : :*
  1045.  * : : : : : : : : 112
  1046.         A.1.2  ifconfig : : : : : : : : : : : : : : : : : : : : : : : : : : : :*
  1047.  *: : : : : : : 114
  1048.         A.1.3  inetd  : : : :: : : : : : : : : : : : : : : : : : : : : : : : : *
  1049.  *: : : : : : : : 117
  1050.         A.1.4  letnet: : : : : : : : : : : : : : : : : : : : : : : : : : : : : *
  1051.  *: : : : : : : : 119
  1052.         A.1.5  offline : : : : : : : : : : : : : :: : : : : : : : : : : : : : :*
  1053.  * : : : : : : : 120
  1054.         A.1.6  online: : : : : : : : : : : : : : : : : : : : : : : : : : : : : *
  1055.  *: : : : : : : : 121
  1056.         A.1.7  ping : : : : : : : : : : : : : : : : : : : : : : : : : : : : : :*
  1057.  *: : : : : : : : 122
  1058.         A.1.8  route  : : : :: : : : : : : : : : : : : : : : : : : : : : : : : *
  1059.  *: : : : : : : : 126
  1060.  
  1061.  
  1062. B  API Function Reference                                                 128
  1063.    B.1  Standard BSD Style Socket Functions: : : : : : : : : : : : : : : : : : *
  1064.  *: : 130
  1065.         B.1.1  accept() : : : : : : : : : : : : : : : : : : : : : : : : : : : :*
  1066.  *: : : : : : : 130
  1067.         B.1.2  bind(): : : : : : : : : : : : : : : : : : : : : : : : : : : : : *
  1068.  *: : : : : : : : 132
  1069.         B.1.3  CloseSocket()  :: : : : : : : : : : : : : : : : : : : : : : : : *
  1070.  *: : : : : : 133
  1071.         B.1.4  connect()  : :: : : : : : : : : : : : : : : : : : : : : : : : : *
  1072.  *: : : : : : : 134
  1073.         B.1.5  Dup2Socket() : : : : : : : : : : : : : : : : : : : : : : : : : :*
  1074.  * :: : : : : 136
  1075.         B.1.6  getpeername()  :: : : : : : : : : : : : : : : : : : : : : : : : *
  1076.  *: : : : : : 137
  1077.         B.1.7  getsockname()  :: : : : : : : : : : : : : : : : : : : : : : : : *
  1078.  *: : : : : : 138
  1079.         B.1.8  getsockopt() : : : : : : : : : : : : : : : : : : : : : : : : : :*
  1080.  * :: : : : : 139
  1081.         B.1.9  IoctlSocket()  :: : : : : : : : : : : : : : : : : : : : : : : : *
  1082.  *: : : : : : 142
  1083.         B.1.10 listen() : : : : : : : : : : : : : : : : : : : : : : : : : : : :*
  1084.  *: : : : : : : 144
  1085.         B.1.11 recv(): : : : : : : : : : : : : : : : : : : : : : : : : : : : : *
  1086.  *: : : : : : : : 145
  1087.         B.1.12 select() : : : : : : : : : : : : : : : : : : : : : : : : : : : :*
  1088.  *: : : : : : : 147
  1089.         B.1.13 send(): : : : : : : : : : : : : : : : : : : : : : : : : : : : : *
  1090.  *: : : : : : : : 150
  1091.         B.1.14 shutdown(): : : : : : : : : : : : : : : : : : : : : : : : : : : *
  1092.  *: : : : : : : 152
  1093.         B.1.15 socket() : : : : : : : : : : : : : : : : : : : : : : : : : : : :*
  1094.  *: : : : : : : 153
  1095.    B.2  Other BSD Functions Related to Sockets : : : : : : : : : : : : : : : : *
  1096.  *: 156
  1097.         B.2.1  getdtablesize() : : : : : : : : : : : :: : : : : : : : : : : : :*
  1098.  * : : : : : 156
  1099.         B.2.2  Syslog() : : : : : : : : : : : : : : : : : : : : : : : : : : : :*
  1100.  *: : : : : : : 157
  1101.    B.3  Network Data and Address Manipulation : : : : : : : : : : : : : : : : :*
  1102.  * : 159
  1103.         B.3.1  inet_addr() : : : : : : : : : : : : : : : : :: : : : : : : : : :*
  1104.  * : : : : : : 159
  1105.    B.4  Network, Protocol and Service Queries : : : : : : : : : : : : : : : : :*
  1106.  * : 162
  1107.         B.4.1  gethostbyname() : : : : : : : : : : : :: : : : : : : : : : : : :*
  1108.  * : : : : : 162
  1109.         B.4.2  getnetbyname(): : : : : : : : : : : : : : : : : : : : : : : : : *
  1110.  *: : : : : : 164
  1111.         B.4.3  getprotobyname() : : : : : : : : : : : : : : : : : : : : : : : :*
  1112.  * : :: : : 166
  1113.         B.4.4  getservbyname() : : : : : : : : : : : :: : : : : : : : : : : : :*
  1114.  * : : : : : 167
  1115.    B.5  AmiTCP/IP Specific Extensions : : : : : : : : : : : : : : : : : : : : :*
  1116.  * : : : 169
  1117.         B.5.1  Errno() : : : : : : : : : : : : : :: : : : : : : : : : : : : : :*
  1118.  * : : : : : : : 169
  1119.         B.5.2  ObtainSocket(): : : : : : : : : : : : : : : : : : : : : : : : : *
  1120.  *: : : : : : 170
  1121.         B.5.3  ReleaseCopyOfSocket() : : : : : : : : : : : : : : : : : : : : : *
  1122.  *: : : : 171
  1123.         B.5.4  ReleaseSocket() : : : : : : : : : : : :: : : : : : : : : : : : :*
  1124.  * : : : : : 172
  1125.  
  1126.  
  1127.  
  1128.                                      xviii
  1129.  
  1130.  
  1131.  
  1132.  
  1133.  
  1134.         B.5.5  SetDTableSize() : : : : : : : : : : : :: : : : : : : : : : : : :*
  1135.  * : : : : : 173
  1136.         B.5.6  SetErrnoPtr()  :: : : : : : : : : : : : : : : : : : : : : : : : *
  1137.  *: : : : : : 174
  1138.         B.5.7  SetSocketSignals(): : : : : : : : : : : : : : : : : : : : : : : *
  1139.  *: : : : : 175
  1140.  
  1141.  
  1142. C  AmiTCP/IP Network Link Library                                        176
  1143.    C.1  net.lib Functions : : : : : : : : : : : : : : : : : : : : : : : : : : :*
  1144.  * : : : : : : 177
  1145.         C.1.1  autoinit : : : : : : : : : : : : : : : : : : : : : : : : : : : :*
  1146.  *: : : : : : : 177
  1147.         C.1.2  autoinitd  : :: : : : : : : : : : : : : : : : : : : : : : : : : *
  1148.  *: : : : : : : 178
  1149.         C.1.3  charRead : : : : : : : : : : : : : : : : : : : : : : : : : : : :*
  1150.  *: : : : : : : 179
  1151.         C.1.4  gethostname : : : : : : : : : : : : :: : : : : : : : : : : : : :*
  1152.  * : : : : : : 181
  1153.         C.1.5  lineRead : : : : : : : : : : : : : : : : : : : : : : : : : : : :*
  1154.  *: : : : : : : 182
  1155.  
  1156.  
  1157. D  Protocols and Network Interfaces                                      185
  1158.    D.1  Protocols and Network Interfaces : : : : : : : : : : : :: : : : : : : :*
  1159.  * : : 186
  1160.         D.1.1  arp : : : : : : : : : : : : : : : :: : : : : : : : : : : : : : :*
  1161.  * : : : : : : : : 186
  1162.         D.1.2  icmp : : : : : : : : : : : : : : : : : : : : : : : : : : : : : :*
  1163.  *: : : : : : : : 189
  1164.         D.1.3  if : :: : : : : : : : : : : : : : : : : : : : : : : : : : : : : *
  1165.  *: : : : : : : : :190
  1166.         D.1.4  inet : : : : : : : : : : : : : : : : : : : : : : : : : : : : : :*
  1167.  *: : : : : : : : 193
  1168.         D.1.5  ip : :: : : : : : : : : : : : : : : : : : : : : : : : : : : : : *
  1169.  *: : : : : : : : :196
  1170.         D.1.6  lo : :: : : : : : : : : : : : : : : : : : : : : : : : : : : : : *
  1171.  *: : : : : : : : :198
  1172.         D.1.7  routing : : : : : : : : : : : : : :: : : : : : : : : : : : : : :*
  1173.  * : : : : : : : 199
  1174.         D.1.8  tcp : : : : : : : : : : : : : : : :: : : : : : : : : : : : : : :*
  1175.  * : : : : : : : : 201
  1176.         D.1.9  udp : : : : : : : : : : : : : : : :: : : : : : : : : : : : : : :*
  1177.  * : : : : : : : : 203
  1178.  
  1179.  
  1180. Glossary                                                                   205
  1181.  
  1182.  
  1183. Bibliography                                                               209
  1184.  
  1185.  
  1186.  
  1187.                                       xix
  1188.  
  1189.  
  1190.  
  1191.  
  1192.  
  1193. xx
  1194.  
  1195.  
  1196.  
  1197.  
  1198.  
  1199. Chapter 1
  1200.  
  1201.  
  1202.  
  1203. User's  Manual
  1204.  
  1205.  
  1206.  
  1207. 1.1     Installation
  1208.  
  1209.  
  1210. AmiTCP/IP installation is made by standard Commodore Amiga Installer
  1211. which provides an easy installation.  Before you can proceed, you should
  1212. acquire some information, list of whichfollows.
  1213.    Your should ask your local network administrator for few things to be
  1214. able to connect your Amiga to a network.  Take this page or copy of it
  1215. with you to make sure that you don't forget anything:
  1216.  
  1217.  
  1218.  1. Internet protocol address allocated for your computer.  This is a
  1219.     series of four decimal numbers separated by dots.  For example,
  1220.     ``130.233.161.40'' is a legal internet address.
  1221.  
  1222.  2. Destination IP address of a point--to--point link.  This applies only
  1223.     if you use a point--to--point medium, such as a serial line.
  1224.  
  1225.  
  1226.  3. Netmask for your network1 This determines which part of your internet
  1227.     address is used to specify the network.  Netmask is like
  1228.     ``255.255.255.0''.  If you do not supply this value, a default
  1229.     computed from the IP address is used.
  1230.  
  1231.  4. Name of your host.  This is a mnemonic name which can usually be used
  1232.     instead of the internet address to refer to your computer.  This is
  1233.     like ``Amiga1''.
  1234.  
  1235.  5. Domain name of your site.  For example, ``hut.fi'' is the domain name
  1236.     for the Helsinki University of Technology in Finland.
  1237.  
  1238.  6. Address(es) of the Domain Name Server(s) which will be used to
  1239.     translate host names to corresponding internet addresses.  A local
  1240.     host database must be used instead if there is no name server on your
  1241.     domain.
  1242.  
  1243.  7. Address of the default gateway via which to send packets to the hosts
  1244.     not on your local network.  There may be more than one of them.
  1245. ________________________________
  1246.    1Netmask is usually needed onlyif you are connected to several
  1247.  
  1248. networks or a network capable to broadcasts.
  1249.  
  1250.  
  1251.  
  1252.                                        1
  1253.  
  1254.  
  1255. 2    Section 1.1                  AmiTCP/IP                    System Manual
  1256.  
  1257.  
  1258.  
  1259.  8. The network interface to use.  This may be Ethernet, SLIP or
  1260.     something else.  We assume that you have proper hardware installed
  1261.     and the appropriate Sana-II compatible device driver installed in
  1262.     directory Devs:networks.  AmiTCP/IP needs the name of the device
  1263.     driver in order to use it.  The unit number for the device in
  1264.     question is also needed (usually this is 0).
  1265.  
  1266.    Installation starts by double-clicking the Install_AmiTCP-2.0-icon of
  1267. the distribution disc.  You can select the level whichspecifies how many
  1268. choices are left to you by the installation script.   After a successful
  1269. installation your computer is ready to communicate with the network.  See
  1270. the file README.FIRST for more information about the installation
  1271. procedure.
  1272.    If you plan to compile applications which use AmiTCP/IP, you should
  1273. add two AmigaDOS assigns for the compiler to find appropriate files.
  1274. Assign the name NETINCLUDE: to the netinclude directory of the AmiTCP/IP
  1275. and the name NETLIB: to the directory netlib.
  1276.  
  1277.  
  1278.  
  1279. 1.1.1   Using the SLIP Drivers
  1280.  
  1281. Some Commodore-Amiga Networking Group supplied SANA-II drivers are
  1282. distributed with the AmiTCP/IP. The SLIPdrivers included are taken from
  1283. Olaf Seibert's distribution and has somebug fixes over the version 37.3.
  1284. See the file doc/slip.doc for installinginstructions for these drivers.
  1285.    The version number of the included slip.device is 37.4.  You can use
  1286. this or newer SLIP driver with AmiTCP/IPwith certain precautions.  The
  1287. included CSLIP device is similar to theSLIP device, it only uses the Van
  1288. Jacobson header compression (see [Jacobson 1990 ] fordescription of this
  1289. compression method).  If your network connection supports CSLIP, you can
  1290. use cslip.device instead of slip.devicein all examples given in this
  1291. section.
  1292.    Used serial interface, baud rate and other parameters for the unit 0 of
  1293. the SLIP device are specified in the configuration file
  1294. ENV:Sana2/slip0.config.  You must edit this file according your system
  1295. setup before you can use the slip device.   Copy the edited file to both
  1296. ENVARC:Sana2 and ENV:Sana2 directories.
  1297.    The AmiTCP/IP opens the slip device driver when given a following
  1298.  
  1299. ifconfig2 command:
  1300.  
  1301. ifconfig slip.device/0 local-address remote-address
  1302.  
  1303. The local-address is the IP address (orname) given to your host, the
  1304. remote-address is the IP address (or name) of the host you are connecting
  1305. to with the serial line.  You should also add a routingentry with the
  1306. route command, for example
  1307.  
  1308. route add default remote-address
  1309.  
  1310. You can test your SLIP connection immediately with the command
  1311.  
  1312. ping remote-address
  1313. ________________________________
  1314.    2The ifconfig and route commands like described here are normally placed to
  1315.  
  1316. the startnet script during AmiTCP/IP installation.
  1317.  
  1318.  
  1319. System Manual                   AmiTCP/IP                   Section 1.2    3
  1320.  
  1321.  
  1322.  
  1323. Common Problems with the SLIP Driver AndAmiTCP/IP
  1324.  
  1325. The ifconfig command gives you the following error message, if there is
  1326. some problems opening the interface:
  1327.  
  1328.  
  1329. ifconfig: ioctl (SIOCGIFFLAGS): no suchinterface
  1330.  
  1331.  
  1332. If the device driver is not installed properly or there is no
  1333. configuration file, AmiTCP/IP gives thefollowing log message:
  1334.  
  1335.  
  1336. <3> OpenDevice: Device or unit failed toopen
  1337.  
  1338.  
  1339. In this case, you should check that thefile ENV:Sana2/slip0.config
  1340. actually exists and the device driver isin the correct directory.
  1341.    If the device driver is ok, but the needed serial device is busy (or
  1342. you have set the slip driver to offlinestate), AmiTCP/IP logs the
  1343. following message:
  1344.  
  1345.  
  1346. <3> slip.device: Device driver is offline (Unit is currently offline)
  1347.  
  1348.  
  1349. Then you must free the serial interface,set the slip device to the
  1350. online state and give the previous ifconfig command with the ``up''
  1351.  
  1352. option3 again.
  1353.    If AmiTCP/IP gives no error messages and the serial link still does
  1354. not work, it may be due to incorrect information in the
  1355. ENV:Sana2/slip0.config-file.  Check thatthe baud rate is correct.  Note
  1356. that the slip device loads the configuration file only on startup, which
  1357. means that you must restart the AmiTCP/IP if you have already configured
  1358. the slip driver with an ifconfig command.
  1359.  
  1360.  
  1361.  
  1362. 1.2     Configuration
  1363.  
  1364.  
  1365. AmiTCP/IP is normally started from the command line with a startup
  1366. script.  It starts the AmiTCP/IP process, which loads the configuration
  1367. files.  The script also contains ifconfig and route commands to open the
  1368. SANA-II device drivers and add the needed route entries, respectively.
  1369.    The AmiTCP/IP can be configured with both option files and ARexx
  1370. commands.  The option files are stored in the text format and they can be
  1371. edited with any text editor.  The '#' character startsa comment, which
  1372. continues to the end of the line.  All configuration commands are
  1373. presented in the section 2.4 starting from the page 17.
  1374.    Configuration files for AmiTCP/IP are stored in the directory
  1375. AmiTCP:db.  It contains at least following files:
  1376.  
  1377.  
  1378. AmiTCP:db/AmiTCP.config   AmiTCP/IPinternal configuration.
  1379.  
  1380.  
  1381. AmiTCP:db/netdb  Network database information, ie.  host names, networks,
  1382.     services, protocols, domain name servers and domains.
  1383. ________________________________
  1384.    3The up is needed because the AmiTCP/IP implicitly adds this option when
  1385.  
  1386. an address to the interface is first given.   If the second ifconfig specifies
  1387. the same address as before, the up option must be given explicitly.
  1388.  
  1389.  
  1390. 4    Section 1.3                  AmiTCP/IP                    System Manual
  1391.  
  1392.  
  1393.  
  1394. AmiTCP:db/hosts.equiv  Host equivalence data used by rlogind, rshd etc.
  1395.     (these daemons are currently unimplemented).
  1396.  
  1397. AmiTCP:db/inetd.conf  Services provided by Inetd, the internet super
  1398.     server.
  1399.  
  1400.  
  1401.  
  1402. 1.2.1   Options
  1403.  
  1404. Normally AmiTCP/IP reads options from the file AmiTCP:db/AmiTCP.config.
  1405. You can specify an option file also on the command line (eg.  AmiTCP WITH
  1406. myopts) or with the tool type WITH. Youcan prevent AmiTCP/IP from
  1407. loading the default option file by the NOCONFIG command line option.
  1408.  
  1409.  
  1410.  
  1411. 1.2.2   Network  Database
  1412.  
  1413. The file AmiTCP:db/netdb is used to store the local net and host name
  1414. information.  There is an example file in the distribution, which you
  1415. must change according to your local network environment.  The syntax for
  1416. the network database file is same as thesyntax for the Arexx command add
  1417. (see page 19).
  1418.    The mostimportant entries are the name of your own host and the
  1419. important hosts in your local net.  For instance, if your host name is
  1420. amiga1.hut.fi and your internet address(IP number) is 130.233.61.50,
  1421. then there is probably a following linein your AmiTCP:db/netdb file:
  1422.  
  1423.  
  1424.      HOST 130.233.61.50 amiga1.hut.fi amiga1 amy1
  1425.  
  1426.  
  1427.    The firstentry after the keyword HOST is the internet address of your
  1428. host.  It is followed by the official name and an optional list of alias
  1429. names to your host.
  1430.    Normally,all host and network names will be translated to the actual
  1431. internet addresses by a name server.  If you can not use the name
  1432. service, then all host names must be inthe AmiTCP:db/netdb file or in an
  1433. included file.  In that case it may be easiest to copythe /etc/hosts
  1434. file from a nearby Unix machine.
  1435.    You can add host names to the network database with ARexx commands at
  1436. any time.  For instance, the following command adds a host called
  1437. vipunen:
  1438.  
  1439. rx "address AMITCP add host 130.233.224.20 vipunen.hut.fi vipunen"
  1440.  
  1441.    There arealso service and protocol entries in the network database
  1442. files.  Do not change them if you are not an expert user.
  1443.  
  1444.  
  1445.  
  1446. 1.3     Internet Addressing
  1447.  
  1448.  
  1449. Each host in the Internet must have an unique 32 bit binary address.
  1450. This address identifies the location ofhost in the internet in an
  1451. unambiguous way.  The internet address is divided intoa net part and a
  1452. host part.  Because of this elegant feature a single address identifies a
  1453. unique host as well as the network whichthe computer is connected to.
  1454.  
  1455.  
  1456. System Manual                   AmiTCP/IP                   Section 1.3    5
  1457.  
  1458.  
  1459.  
  1460.    When selecting a route to a particular host the whole address is
  1461. considered first.  If no direct route to the host can be found, a route
  1462. to the host's network can be considered.  If no route to either host or
  1463. net can be found, the packet is sent tothe default gateway.
  1464.    Because the the internet address defines also the network which the
  1465. computer is connected, they must actually be given one per network
  1466. connection.  If a host is directly connected to severalnetworks, it has
  1467. also several distinct internet addresses.
  1468.  
  1469.  
  1470.  
  1471. 1.3.1   Internet Dot Notation
  1472.  
  1473.  
  1474. Since it is rather inconvenient to use 32-bit integers, the internet
  1475. address is normally written in the Internet dot notation.  It is a series
  1476. of decimal numbers separated by dots.
  1477.  
  1478.  
  1479.               ____________________________________________________
  1480.               !_Format__!Size______________________!Example_______!
  1481.               ! a       !32-bit                    !169510179    !
  1482.               ! a.b     !8-bit.24-bit             !10.1738019   !
  1483.               ! a.b.c   !8-bit.8-bit.16-bit       !10.26.34083  !
  1484.               !_a.b.c.d_!8-bit.8-bit.8-bit.8-bit_!_10.26.133.35_!_
  1485.  
  1486.  
  1487.  
  1488.          Table 1.1:  Four different forms for an Internet address.
  1489.  
  1490.  
  1491.    The one with four separate octets is the most common form of the
  1492. notation.  See the reference for the function
  1493. bsdsocket.library/inet_addr() to additional information (at Appendix
  1494. B.3.1, page 159).
  1495.  
  1496.  
  1497.  
  1498. 1.3.2   Nets and Routing
  1499.  
  1500.  
  1501.  
  1502.                 0_1_2_3_4______8_____________16____________24___________31_
  1503.                 ! !           !                                            !
  1504.        Class A  !!0!!Netpart  !!                Hostpart                   !!
  1505.                 __________________________________________________________
  1506.                 __________________________________________________________!!!!!
  1507.  
  1508.        Class B  !!1!!0!!     Netpart         !!        Hostpart            !!
  1509.                 __________________________________________________________
  1510.                 __________________________________________________________!!!!!!
  1511.  
  1512.        Class C  !!1!!1!!0!!          Netpart               !! Hostpart     !!
  1513.                 __________________________________________________________
  1514.                 __________________________________________________________!!!!!!
  1515.  
  1516.        Class D  !!1!!1!!1!!0!!         Multicast Address                   !!
  1517.                 __________________________________________________________
  1518.                 __________________________________________________________!!!!!*
  1519.  *!!
  1520.  
  1521.        Class E  !!1!!1!!1!!1!!0!!      Experimental Address                !!
  1522.                 __________________________________________________________
  1523.  
  1524.  
  1525. Figure 1.1:  The Internet address classes.  The different address classes
  1526. can be identified by few first bits.
  1527.  
  1528.  
  1529. 6    Section 1.3                  AmiTCP/IP                    System Manual
  1530.  
  1531.  
  1532.  
  1533.    There arefive classes of internet addresses in use, namely A, B, C, D
  1534. and E classes.  The difference between address classesis the length of
  1535. the network and host part.  An A class address has 7 bits for net address
  1536. and 24 bits for host address, a B classaddress has 14 bits for net and
  1537. 16 bits for host and a C class address has 21 bits for net and 8 bits for
  1538. host.  The D class is used for the IP multicast addresses and the E class
  1539. for experimental use only4.
  1540.    The address class can be determined by the first octet of the address.
  1541. If it is in the range 0---127, the address belongs to the A class.  If it
  1542. is 128--191, the address belongs to theB class.   If the first octet is
  1543. 192--223, the address belongs to the C class, otherwise it is an
  1544. experimental or a multicast address.
  1545.  
  1546.  
  1547.  
  1548. 1.3.3   Subnets
  1549.  
  1550. The network addresses are managed by a central authority.  Local
  1551. administration manages the host addresses.   Because network addresses are
  1552. used in routing, the central authority is needed when the local network
  1553. changes its structure.  This might be quite a burden tothe central
  1554. authority, but there is a solution developed for the Internet.  A network
  1555. may be split into several subnets, whichcan then be managed by
  1556. independent agencies.  The central network management doesn't have to
  1557. know anything about subnets and hosts inthem.
  1558.    For instance Kone corporation has been assigned a B class network
  1559. 138.249.0.0.  This network has been divided to C classlike subnets,
  1560. which are then given to the departments.  The HAT department is given
  1561. subnet 138.249.2.0, the HATMEC department subnet 138.249.5.0 and so on.
  1562.                  0________8________16______24_______
  1563.  
  1564.       Address    !!_________________________________1!138.249.!02.03001010!!111*
  1565.  *11001!!00000010!!00011110
  1566.  
  1567.                  ___________________________________
  1568.  AND  Netmask    !!_________________________________1!255.255.255.!10111111!!11*
  1569.  *111111!!11111111!!00000000
  1570. _______________________________________________________________________
  1571.  
  1572.   =    Subnet    !!_________________________________1!138.249.!02.0001010!!1111*
  1573.  *1001!!00000010!!00000000
  1574.  
  1575.  
  1576.  
  1577.         Figure 1.2:  Using netmask to find out subnetwork address.
  1578.  
  1579.  
  1580.    The subnet division is controlled by the netmask parameter.  The actual
  1581. subnetwork address is obtained by bit-wise AND between the netmask and
  1582. the internet address.  This subnet address is used in routing just like a
  1583. normal net address.  However, only hosts directly connected to the
  1584. divided net have to know anything aboutnetmasks and subnets.
  1585.  
  1586.  
  1587.  
  1588. 1.3.4   Broadcast Addresses
  1589.  
  1590. There are two kind of broadcast addresses in the Internet.  An obsolete
  1591. form used in older BSD 4 versions used internet address with host part 0
  1592. ________________________________
  1593.    4Routers not taking part to such experiments normally discard all
  1594.  
  1595. packets of this class.
  1596.  
  1597.  
  1598. System Manual                   AmiTCP/IP                   Section 1.4    7
  1599.  
  1600.  
  1601.  
  1602. as the broadcast address.  (The newer software usuallyconsiders
  1603. addresses like those as network addresses.)   Accordingthe the current
  1604. Internet standard the broadcast addresses have the host part all 1's.
  1605.  
  1606.  
  1607.       ___________________________________________________________________
  1608.       !   Interface    !                !   Network     !  Broadcast     !
  1609.       !                !  Netmask       !               !                !
  1610.       !    Address     !                !   Address     !   Address      !
  1611.       !________________!________________!_______________!________________!
  1612.       ! 10.14.123.2   !255.255.255.0   ! 10.14.123.0   ! 10.14.123.255  !
  1613.       ! 130.244.5.4   !255.255.255.128 ! 130.244.5.0   ! 130.244.5.127  !
  1614.       !_192.36.148.21_!255.255.255.0___!_192.36.148.0__!_192.36.148.255_!_
  1615.  
  1616.  
  1617.  
  1618. Table 1.2:  Examples of netmasks, network addresses andbroadcast
  1619. addresses.
  1620.  
  1621.  
  1622.  
  1623. 1.4     Utilities
  1624.  
  1625.  
  1626. Currently, only a few networking utilities are ported for the AmiTCP/IP.
  1627. They are used to monitor and control network operation with AmiTCP/IP.
  1628. There is a separate reference entry foreach network utility and daemon
  1629. in the document file netutil.doc.  This autodoc file isincluded in the
  1630. appendix A, starting from page 111.
  1631.  
  1632.  
  1633.  
  1634. 1.4.1   arp
  1635.  
  1636. arp displays and modifies the internet to hardware address translation
  1637. tables used by the Address Resolution Protocol.   It isused if you are
  1638. connected to a broadcast network, eg.  Ethernet or Arcnet.  You may
  1639. examine, add, and delete ARP entries.  Usually arp is used to find out
  1640. hardware address of hosts.
  1641.    The hardware addresses are given as hexadecimal strings, each octet
  1642. separated by a colon.
  1643.    Examples:
  1644.  
  1645.  
  1646.  1.> arp -s puucee 8:0:9:32:f2:4c pub
  1647.  
  1648.     This command sets the hardware address for the host 'puucee' as
  1649.     '8:0:9:32:f2:4c'.
  1650.  
  1651.  
  1652.  
  1653. 1.4.2   ifconfig
  1654.  
  1655. ifconfig configures network interface parameters.   Itassigns an internet
  1656. address to a SANA-II network interface or sets interface parameters.
  1657. ifconfig is normally used at the AmiTCP/IP startup.
  1658.    Examples:
  1659.  
  1660.  
  1661.  1.> ifconfig lo/0 127.1
  1662.  
  1663.     This command marks internal loopback device up, and attaches the
  1664.     internet address 127.0.0.1 to it.
  1665.  
  1666.  
  1667. 8    Section 1.4                  AmiTCP/IP                    System Manual
  1668.  
  1669.  
  1670.  
  1671.  1.> ifconfig cslip.device/0 inet 193.102.4.144 193.102.4.129
  1672.  
  1673.     This command starts the CSLIP driver, attaches an address
  1674.     193.102.4.144 (our internet address) and a destination address
  1675.     193.102.4.129 (the internet address of the host you are connecting)
  1676.     to it.
  1677.  
  1678.  
  1679.  1.> ifconfig a2065.device/0 inet 193.124.100.66 +
  1680.     netmask 255.255.255.192 up -arp
  1681.  
  1682.     This command loads an ethernet driver for the Commodore A2065
  1683.     Ethernet adapter unit 0, marks it UP, disables ARP protocol for it,
  1684.     attaches an inet address 193.124.100.66 to it and sets its netmask to
  1685.     255.255.255.192.  A bitwise logical AND of the netmask and the
  1686.     address for the interface forms the subnet address, in this case
  1687.     193.124.100.66.  All packets aimed to hosts with same subnet address
  1688.     (that is hosts 193.124.100.65--193.124.100.126) are routed to this
  1689.     interface.
  1690.  
  1691.  
  1692.  
  1693. 1.4.3   letnet
  1694.  
  1695. letnet is a simple TCP connection tool.  With it you can connect to a TCP
  1696. port at given host.  Letnet reads data from standard input and sends it
  1697. to the host.  Likewise it receives data from the connection and writes it
  1698. to the standard output.  Letnet terminates upon shutdown of the socket or
  1699. receiving SIGBREAKF_CTRL_C signal.  Letnet does not handle telnet
  1700. protocol.
  1701.  
  1702.  
  1703.  
  1704. 1.4.4   netstat
  1705.  
  1706. netstat shows network status.  It symbolically displaysinformation of
  1707. network data structures of the AmiTCP/IP. There are several standard
  1708. AmigaDOS style options:
  1709.  
  1710.  
  1711.  By default displays all sockets that are not listening.
  1712.  
  1713.  
  1714. ALL displays all sockets.
  1715.  
  1716.  
  1717. STATUS displays values of several protocol-related variables.
  1718.  
  1719.  
  1720.    Example:
  1721.  
  1722.  
  1723.  1.> netstat status
  1724.  
  1725.  
  1726.    Netstat is an ARexx script which uses the AMITCP port of the AmiTCP/IP
  1727. to collect the information.  See section2.5.1 (p.  18) for details about
  1728. the ARexx commands supported by the AmiTCP/IP.
  1729.  
  1730.  
  1731.  
  1732. 1.4.5   NapsaTerm
  1733.  
  1734. NapsaTerm is a VT102 terminal emulator for logging remotely to Unix hosts
  1735. with rlogin protocol.  It is based on the NiftyTerm version 1.2 for Amiga
  1736. by Chris Newman and William Todd.
  1737.  
  1738.  
  1739. System Manual                   AmiTCP/IP                   Section 1.5    9
  1740.  
  1741.  
  1742.  
  1743.  1.> run napsaterm -d net happi.hut.fi
  1744.  
  1745.     This command starts VT102 emulator with a rlogin connection to the
  1746.     host happi.hut.fi.
  1747.  
  1748.  
  1749.  
  1750. 1.4.6   offline
  1751.  
  1752. offline5 sends the S2_OFFLINE command to thegiven SANA-II device driver.
  1753. This command is normally used to disconnect SANA-II device driver from
  1754. the network adapter hardware.  After this command the device driver does
  1755. not accept any more read or write requests.
  1756.    Example:
  1757.  
  1758.  1.> offline slip.device/0
  1759.  
  1760.     This command puts the SLIP driver unit 0 offline, which frees then
  1761.     the serial port to other use.
  1762.  
  1763.  
  1764.  
  1765. 1.4.7   online
  1766.  
  1767. online sends the S2_ONLINE command to the given SANA-II device driver.
  1768. The device driver restarts the network adapter hardware and accepts read
  1769. and write request again.
  1770.    Example:
  1771.  
  1772.  1.> online a2066.device/0
  1773.  
  1774.     This command tries to start the Commodore ARCNET network adapter.
  1775.  
  1776.  
  1777.  
  1778. 1.4.8   route
  1779.  
  1780. route manipulates the routing tables.  It is normally used at the
  1781. AmiTCP/IP startup sequence to provide the default routing information in
  1782. the routing tables.  All needed routing information canbe provided with
  1783. this command.
  1784.    Routes determine into which network IP packets are sent.  Usually there
  1785. is only need to set the default route toyour gateway and the route to
  1786. the host itself through the loopback device.   More route entries may be
  1787. needed if your host is used as a gateway.
  1788.  
  1789.  
  1790.  
  1791. 1.5     Errors  and  Logging
  1792.  
  1793.  
  1794. There are two kinds of error reports AmiTCP/IP produces:
  1795.  
  1796. Errors might be produced when a user process or a network supplies
  1797.     invalid data.  These don't cause any problems to AmiTCP/IP. These
  1798.  
  1799.     events are logged6 to help the user to find out possible problems
  1800.     with his/her system.
  1801. ________________________________
  1802.    5offline and online are compatible with the Commodore supplied SANA-II
  1803.  
  1804. utilities with same names.  However, they support the AmiTCP/IP naming
  1805. convention.
  1806.    6if logging is not disabled
  1807.  
  1808.  
  1809. 10    Section 1.7                  AmiTCP/IP                   System Manual
  1810.  
  1811.  
  1812.  
  1813. Failures are more serious.  These mean that AmiTCP/IP has entered to
  1814.     state where there is no way out.
  1815.  
  1816.     In Unix systems these cases lead to panic() and immediate restart.
  1817.     This is because in Unix systems networking software is integral part
  1818.     of the kernel and if something goes wrong, it usually means that the
  1819.     whole kernel is corrupted.  This is not the case in Amiga and
  1820.     AmiTCP/IP, however.  As AmiTCP/IP runs as a normal process, rest of
  1821.     the system can work even if networking fails.
  1822.  
  1823.  
  1824.    In Unix systems the syslogd takes care of the error reporting using an
  1825. attached console.  In AmigaOS there is no general failure reporting
  1826. system, only User Requesters which are inadequate for non-interactive
  1827. use.  As logging could be used even while in interruptlevel, AmiTCP/IP
  1828. can't write to log-files itself.  This is why the actual logging is done
  1829. by the NETTRACE process.  It is started at AmiTCP/IP startup and can be
  1830. configured through AMITCP ARexx port.
  1831.    ARexx commands can be found in section 2.5.1 (p.  18).
  1832.  
  1833.  
  1834.  
  1835. 1.6     Troubleshooting
  1836.  
  1837.  
  1838. This section is reserved for the frequently asked questions and answers
  1839. to them.
  1840.  
  1841.  
  1842.  
  1843. 1.7     Testing Utilities
  1844.  
  1845.  
  1846.  
  1847. There are two testing utilities providedwith the AmiTCP/IP. The agnet7
  1848. controls the loopback pseudo device which simulates different networks.
  1849. The qwriter simulates some typical application programs.  They can be
  1850. used together to test the integrity of the protocol stack.
  1851.  
  1852.  
  1853.  
  1854. 1.7.1   Agnet
  1855.  
  1856.  
  1857. SANA-II pseudo device driver agnet.device works as a network between its
  1858. units.  Packets from one unit are sent to another according given
  1859. destination address.  You can also arrange an unit-to-unit connection, if
  1860. you want to simulate point-to-point devices.
  1861.    The loopback device provides nearly full SANA-II device driver
  1862. functionality.  It provides different hardware types, packet types and
  1863. the variable hardware address width from0 to 128 bits.  It collects all
  1864. the required statistics.  It does not provide the multicast
  1865. functionality.
  1866.    A specialcommand file env:sana2/agnetn.config is used to configure and
  1867. control the device.  Configuration parameters may be specified by
  1868. supplying its keyword and the wanted value.   Any parameter may be left
  1869. out.
  1870. ________________________________
  1871.    7As Good NETwork as you like
  1872.  
  1873.  
  1874. System Manual                   AmiTCP/IP                   Section 1.7    11
  1875.  
  1876.  
  1877.  
  1878.    The configuration file parsing template is
  1879. WIRE/K,MTU/N/K,MINTU/N/K,BPS/N/K,ADDR=ADDRESS/K,
  1880. DELAY/N/K,DEV=DEVIATION/N/K,ERRORS/K/N,LOSS/K/N,DST=DSTUNIT/K/N.8
  1881.    User configurable parameters are:
  1882.  
  1883. WIRE hwiretypei is the hardware type which device driver will report.
  1884.     Other default parameters are set according to it.  Default hardware
  1885.     type is Ethernet.  With different wire types you can test for
  1886.     instance Ethernet specific features of AmiTCP/IP without killing the
  1887.     whole Ethernet segment of your network.
  1888.  
  1889. ADDRESS hhardware addressi  is the hardware addresses for the unit.
  1890.     Address is specified as a hexadecimal octet string.  Octets are
  1891.     separated by colons.  The length of the address depends of the
  1892.     hardware type.  For example, 8:0:9:14:74:53 is a legal Ethernet
  1893.     hardware address.  Alias:  ADDR.
  1894.  
  1895. DSTUNIT hunit numberi  is the destination unit for a unit-to-unit
  1896.     connection.  If this parameter is given, all packets sent to the unit
  1897.     are relayed to specified destination unit regardless of the packet
  1898.     destination address.
  1899.  
  1900. MTU hnumber of octetsi  is the maximum packet size that pseudo network will
  1901.     accept.  Default value is 1500 octets, same as the MTU for the
  1902.     Ethernet.
  1903.  
  1904. MINMTU hnumber of octetsi  is the minimum packet size that pseudo network
  1905.     will accept.  Smaller packets are padded to this minimum length.
  1906.     Default value depends on the hardware.  It is for instance 46 octets
  1907.     for the Ethernet.
  1908.  
  1909. BPS htransmission speedi  is the bit speed which device driver will report
  1910.     to the user.
  1911.  
  1912. DELAY hdelay timei specifies the delay of network in milliseconds.  By
  1913.     default there is no delay.
  1914.  
  1915. DEVIATION hstandard deviationi  specifies delay variance in milliseconds.
  1916.     Packets are delayed randomly which means that packets may arrive in
  1917.     different order they were sent.  Deviation without delay is
  1918.     meaningless.  By default the variance is 0 ms and all packets have
  1919.     same delay.
  1920.  
  1921. ERRORS hprobabilityi  is theprobability of bit errors.  This value can be
  1922.     in range [0..100 000 000], ERRORS/100 000 000 indicating probability
  1923.     of a single bit error.  Error rate 100 000 000 means that all bits
  1924.     have random value.  By default there are no errors (value 0).
  1925.  
  1926. LOSS hprobabilityi defines the probability of the packet loss.  This is a
  1927.     number in the range [0..1 000 000], LOSS/1 000 000 indicating
  1928.     probability.  By default there is no packet loss.  Note that value
  1929.     1 000 000 means that all packets are lost.
  1930.  
  1931. ________________________________
  1932.    8Alternative forms of keywordsare specified by using alt=keyword.
  1933.  
  1934. Modifier /N specifies that the parameteris numeric.
  1935.  
  1936.  
  1937. 12    Section 1.7                  AmiTCP/IP                   System Manual
  1938.  
  1939.  
  1940.  
  1941. ARexx Port for agnet.device
  1942.  
  1943. The Arexx port is normally named as AGNET1.   If thereis multiple
  1944. instances of the agnet.device, the second instance has the port AGNET2
  1945. and so on.
  1946.    There iscurrently three different Arexx commands:
  1947.  
  1948.  
  1949. UNIT Alias:  U
  1950.  
  1951.     Some configuration parameters may be changed at run-time by Arexx
  1952.     commands.  The Arexx configuration commands follow the same syntax as
  1953.     the configuration file.  The user must specify the unit to configure
  1954.     by preceding the command with the keyword (UNIT, abbreviated as U)
  1955.     and a decimal unit number.  For instance, the following is a legal
  1956.     Arexx configuration command:
  1957.  
  1958.  
  1959.     address AGNET1 unit 0 bps 2400 wire slip delay 100
  1960.  
  1961.  
  1962. QUERY Alias:  Q
  1963.  
  1964.     The current configuration may be queried from the device by an ARexx
  1965.     command Q=QUERY. The command keyword is followed by an unit number
  1966.     and wanted configuration parameters.  You can also give a keyword
  1967.     ALL, if you want all configuration parameters.  For example,
  1968.     following command prints wiretype, delay, deviation and loss
  1969.     probability:
  1970.  
  1971.  
  1972.     options results
  1973.     address AGNET1 query 0 wire delay deviation loss
  1974.     say result
  1975.  
  1976.  
  1977. EXIT Aliases:  E, EXPUNGE
  1978.  
  1979.     The device may be expunged from the system memory by this Arexx
  1980.     command.  The command fails, if there are some currently opened
  1981.     units.
  1982.  
  1983.  
  1984. System Manual                   AmiTCP/IP                   Section 1.7    13
  1985.  
  1986.  
  1987.  
  1988. 1.7.2   Qwriter
  1989.  
  1990.  
  1991. qwriter9 works on the application layer.  It is run as two distinct
  1992. processes.  A process acts as a server or a client.  It creates one
  1993. socket and sends and receives data through the socket.  It is able to
  1994. control data consistency and measures both latency times and throughput
  1995. (if appropriate).
  1996.    Server part is started first in all tests.  Server starts to listen to
  1997. a port, and you can start the client.  Tests are configurable, basic test
  1998. types are described below.
  1999.  
  2000.  
  2001. telnet simulates typical interactive use.
  2002.  
  2003.     In this test a TCP connection is created.  The client end sends one
  2004.     character at a time and the server replies with four or more
  2005.     characters at a time.
  2006.  
  2007.     The most important measurement is the latency time between the sent
  2008.     character and the received echo.
  2009.  
  2010. nfs simulates the data transfer of a network file system.
  2011.  
  2012.     In this test UDP messages are sent between processes.
  2013.  
  2014.     Both latency and the throughput are important measurements in this
  2015.     test.
  2016.  
  2017. ftp is a simple TCP connection.
  2018.  
  2019.     In this test a TCP connection is created, then some data is
  2020.     transferred from one end to the another.
  2021.  
  2022.     In this test throughput is the key measurement.
  2023.  
  2024.  
  2025.  
  2026. Command Line Options
  2027.  
  2028. -s Act as a server (default).
  2029.  
  2030. -c Act as a client.
  2031.  
  2032. -t htypei Describes type of test:  ftp, nfs or telnet.  Type can be
  2033.     abbreviated to shortest unique length.  Default is telnet.
  2034.  
  2035. -n hcounti Describes how many times packets are sent back and forth.
  2036.     Applies to nfs and telnet.  Default for hcounti is 1.
  2037.  
  2038. -l hlengthi Describes length of data.  Default is 1000 octets.  Length has
  2039.     different meaning in different test contexts:
  2040.  
  2041.  
  2042.     ftp Length of the requested data for the client.  Length parameter is
  2043.         meaningless for a ``ftp'' server.
  2044.  
  2045.     nfs The size of the packet to be sent to the other end.
  2046.  
  2047.     telnet  The maximum length of data returned from the server.  Actual
  2048.         length is random value between 4 and length octets.  See also
  2049.         option ``-d''.  This parameter is meaningless for a client.
  2050. ________________________________
  2051.    9Quick WRITER
  2052.  
  2053.  
  2054. 14    Section 1.7                  AmiTCP/IP                   System Manual
  2055.  
  2056.  
  2057.  
  2058. -d hn1,n2,: :,:nNiThis option has meaning for the telnet server and
  2059.     overrides the ``-l'' option.  It specifies distibution of data
  2060.     lengths of replied packets to help better simulate typical
  2061.     interactive use where replies are usually short, but sometimes long
  2062.     (few kilobytes).
  2063.  
  2064.     Only k = 2i  N first numbers have effect.   Probability to have length
  2065.     less than nj (1  j  k) is approximately
  2066.  
  2067.  
  2068.                                                  Xk  nj
  2069.                               P (j) = P (j 1) + 1_   ___
  2070.                                                 k    nl
  2071.                                                  l=j
  2072.  
  2073.  
  2074.     (P (0)   =  0) This can vary depending on random numeber generator and
  2075.     because of discret nature of computing.  The largest length is nk.
  2076.  
  2077. -b hsizei Size of the buffer tobe allocated for sends and/or replies.
  2078.     Default is 30 kilobytes.  Amount of data to be send at once, if
  2079.     smaller than data to be sent.  Maximum amount of data to be expected
  2080.     from the other end.
  2081.  
  2082. -p hporti the server port number.   The default is 1500.
  2083.  
  2084. -h hhosti Name of the host to connect.  Has no meaning for servers.  The
  2085.     default is address ``127.0.0.1''.
  2086.  
  2087. -q Calculate checksum and verify returned messages.   Thisprovides way to
  2088.     check for integraty of transferred data.  Checksum method is FCS as
  2089.     described in PPP RFC (1331).
  2090.  
  2091. -T htimeouti Specifies timeout (in seconds) for retransmission.  Only
  2092.     meaningful for nfs client.  The default is 1.0 seconds.
  2093.  
  2094.  
  2095.  
  2096.  
  2097.  
  2098. Chapter 2
  2099.  
  2100.  
  2101.  
  2102. Interfaces
  2103.  
  2104.  
  2105.  
  2106. AmiTCP/IP provides Berkeley sockets compatible interface to the
  2107. application programs.  Networking applications can usethis interface to
  2108. use TCP and UDP protocols, for example.
  2109.    AmiTCP/IPnetworking system uses SANA-II network devices.  SANA-II is
  2110. an Amiga standard network device driverinterface at the data link layer.
  2111.  
  2112.  
  2113.  
  2114. Figure 2.1:  Interfaces between different modules of the AmiTCP/IP
  2115. internetworking system.
  2116.  
  2117.  
  2118.    There isalso a standard ARexx interface for logging, statistics and
  2119. configuration in AmiTCP/IP.
  2120.  
  2121.  
  2122.  
  2123. 2.1     AmiTCP/IP Processes
  2124.  
  2125.  
  2126. AmiTCP/IP uses one protocol process.  The protocol process starts
  2127. listening specified SANA-II device drivers for incoming network frames
  2128.  
  2129.  
  2130.  
  2131.                                       15
  2132.  
  2133.  
  2134. 16    Section 2.3                  AmiTCP/IP                   System Manual
  2135.  
  2136.  
  2137.  
  2138. and sends timeout requests periodicallyto the timer device.  Output to
  2139. the network is usually done in the API callers context concurrently with
  2140. the input processing.
  2141.    There isone other task called NETTRACE taking care of error reporting
  2142. and the ARexx port of the AmiTCP/IP. Thecommands for this port are
  2143. described later in the section 2.5.1.
  2144.  
  2145.  
  2146.  
  2147. 2.2     Application Interface
  2148.  
  2149.  
  2150. Application Interface is implemented asa standard Amiga shared library.
  2151. Each task that opens the library (usingthe OpenLibrary() call) is given
  2152. an unique data area (called a library base), which AmiTCP/IP uses it to
  2153. store task specific information (see section 3.1.2 for more on this
  2154. subject).  Once the library is opened, applications cancall the standard
  2155. socket functions such as socket(), connect(), bind(), listen(), accept(),
  2156. recv() and send().
  2157.  
  2158.  
  2159.  
  2160. 2.3     SANA-II Interface
  2161.  
  2162.  
  2163. AmiTCP/IP can use (hopefully) any SANA-II [SANA-II 1992 ] device.
  2164. However, there may be problems with packet types and addressing.
  2165.    Many protocols may use the same hardware if each protocol uses unique
  2166. packet type number.  For instance, in the Ethernet theIP protocol have
  2167. packet type 2048, the Xerox NS protocoluses the packet type 1536.  The
  2168. device driver directs packets to different protocols depending of their
  2169. type.  IP packet type varies in different hardware, forinstance ARCNET
  2170.  
  2171. uses packet type 240 for IP1.
  2172.    SANA-II devices are required to follow the hardware type numbers
  2173. assigned in the [Reynolds 1990 ].  There is only one hardware typewhich
  2174. for instance all Ethernet drivers shoulduse.   The SANA-II interface
  2175. module uses the hardware type number todetermine packet types for each
  2176. protocol.
  2177.    The hardware level addressing complicates the situation further.  It is
  2178. not possible to provide a general addressing scheme in hardware level.
  2179. AmiTCP/IP can use a driver only if thereis some mapping from IP
  2180. addresses to hardware addresses.
  2181.    SometimesSANA-II network driver uses an IP compatible addressing
  2182.  
  2183. scheme, for instance SLIP or PPP drivers2 use an IP address asthe
  2184. hardware address.  Other solution is to use Address Resolution Protocol
  2185. (ARP). With ARP AmiTCP/IP can map any IPaddress to the corresponding
  2186. hardware address.
  2187.    For installing appropriate SANA-II device driver the manual of the
  2188. device driver should be consulted.  Note that if the device driver is not
  2189. installed into the devs:networks directory, a full path must be specified
  2190. when the driver is first referred to after the startup.
  2191. ________________________________
  2192.    1There is an extension to ARCNET IP that is incompatible with old one.
  2193.  
  2194. It uses packet type 212 for IP.
  2195.    2At the hardware level these protocols do not use addresses at all.
  2196.  
  2197.  
  2198. System Manual                   AmiTCP/IP                   Section 2.5    17
  2199.  
  2200.  
  2201.  
  2202.    A networkdevice driver can be attached to the AmiTCP/IP with ifconfig
  2203. command.  This can be done manually or by the network startup script.
  2204.  
  2205.  
  2206.  
  2207. 2.3.1   Interface ioctls
  2208.  
  2209. The AmiTCP/IP provides an upward compatible ioctl interface to configure
  2210. the network interfaces.  Refer to the autodoc entry protocols/if for
  2211. standard BSD ioctl interface (see appendix D.1.3, page 190).  The
  2212. extension for this interface is meant toconfigure hardware dependent
  2213. parameters in an uniform way.
  2214.    The ARP interface have been modified to be slightly more generic.  The
  2215. length of the hardware address is now passed in the arp_ha address field.
  2216. A new ioctl accesses the contents of thewhole ARP mapping cache.  (In
  2217. the BSD the static ARP table is accessedvia the /dev/kmem.)
  2218.  
  2219.  
  2220.  
  2221. 2.4     Configuration Files
  2222.  
  2223.  
  2224. The initial state of AmiTCP/IP is set bythe configuration files.  The
  2225. syntax differs from one configuration file to another.  For each file
  2226. format there is usual a corresponding ARexx command with the same syntax.
  2227. For instance, configuration options, which are set in the file
  2228. AmiTCP:db/AmiTCP.config, may be set withthe SET command by an ARexx
  2229. script.  The entries of the AmiTCP:db/netdb file can beadded manually
  2230. with the ADD command.
  2231.  
  2232.  
  2233.  
  2234. 2.5     ARexx Interface
  2235.  
  2236.  
  2237. In Amiga environment Exec message portsare standard way to communicate
  2238. between applications.  Because of the ease of programming and the
  2239. efficiency the ARexx programming language has become the standard in the
  2240. Amiga and structure it uses for messagesis also standard.  AmiTCP/IP
  2241. provides ARexx port named AMITCP which can be used to both configure and
  2242. gather information from networking.  This is much moreelegant compared
  2243. to the BSD Unix way to read directly from the kernel memory.
  2244.    The AMITCP port can be used to set and query various variables and
  2245. statistic tables.  Brief example of the usage of the port follows:
  2246.  
  2247.  
  2248. /*c:rexx
  2249.  *
  2250.  * An example to query some informationform AmiTCP/IP
  2251.  */
  2252.  
  2253.  
  2254. address AMITCP
  2255. options results /* get results back */
  2256.  
  2257.  
  2258. 'Q' TASKNAME
  2259. say "Name of amitcp task is" result
  2260. 'SET' TASKNAME "INET"
  2261. 'QUERY' ICMP CHKSUM IP CHKSUM TCP CONNECT UDP CHKSUM TASKNAME
  2262. /* Query count of ICMP, IP and UDP checksums and TCP connects */
  2263.  
  2264.  
  2265. 18    Section 2.5                  AmiTCP/IP                   System Manual
  2266.  
  2267.  
  2268.  
  2269. parse value result with icps_checksum ips_badsum tcps_connects udps_badsum task*
  2270.  *name
  2271. /* Parse values from result. (Names of the variables are from
  2272.  * the stat-structures
  2273.  */
  2274.  
  2275.  
  2276. say "New name is" taskname
  2277.  
  2278.  
  2279. say icps_checksum "bad ICMP checksums"
  2280. say ips_badsum "bad IP header checksums"
  2281. say tcps_connects "TCP connections established (including accepts)"
  2282. say udps_badsum "bad UDP checksums"
  2283.  
  2284.    This example will produce output similar to following:
  2285.  
  2286. Name of amitcp task is AmiTCP
  2287. New name is INET
  2288. 0 bad ICMP checksums
  2289. 0 bad IP header checksums
  2290. 2531 TCP connections established (including accepts)
  2291. 0 bad UDP checksums
  2292.  
  2293.  
  2294.  
  2295. 2.5.1   Commands
  2296.  
  2297. This section summarizes the commands recognized by the ARexx port of the
  2298. AmiTCP/IP. The command lines may containcomments, which are started by
  2299. the semicolon.
  2300.  
  2301. ADD hentryi This command adds entries to thenetwork database.  Templates
  2302.     for the entries are:
  2303.  
  2304.     WITH hfile namei [PREFIX=hentry typei]  Include the file hfile namei.
  2305.         Entry type for the file may be specified with an optional prefix,
  2306.         which may be any of the entry types listed in this list.   The
  2307.         file will be searched first from the AmiTCP:db directory, so that
  2308.         the actual path may be omitted, if the file resides inthat
  2309.         directory.
  2310.         For exmaple,
  2311.         WITH hosts PREFIX=HOST
  2312.         includes the file hosts, which contains only host entries.   The
  2313.         host keyword must not be present at the file itself.
  2314.         The WITH command is useful for including database files
  2315.         downloaded from Unix machines.
  2316.  
  2317.     H=HOST haddressi hnamei [aliases]  Add a host entry to the network
  2318.         database.  Either H or HOST can be used as the keyword. The
  2319.         haddressi is the internet address of the host, the hnamei is the
  2320.         official name and [aliases] is an optional list of alias names
  2321.         for the host.
  2322.         Example:
  2323.         H 128.214.6.100 nic.funet.fi nic
  2324.  
  2325.     N=NET hnamei haddressi [aliases]  Add a net entry to the network
  2326.         database.  Arguments are as above for the HOST.
  2327.         Example:
  2328.  
  2329.  
  2330. System Manual                   AmiTCP/IP                   Section 2.5    19
  2331.  
  2332.  
  2333.  
  2334.         N loopback-net 127 software-loopback-net
  2335.  
  2336.     S=SERVICE hnamei hporti/hprotocoli [aliases]  Add a service entry to the
  2337.         network database.  The hporti is the port number for the hprotocoli
  2338.         for which the server for the service will listen for the service
  2339.         requests.  [aliases] is as above.
  2340.         Example:
  2341.  
  2342.         S daytime 13/tcp
  2343.  
  2344.     P=PROTOCOL hnamei hprotocol numberi [aliases]   Add a protocol entry to
  2345.         the network database.
  2346.         Example:
  2347.  
  2348.         P tcp 6
  2349.  
  2350.     NS=NAMESERVER haddressi  Add a name server entry to the network
  2351.         database.  The haddressi is the address of the name server in the
  2352.         internet dot-notation.  The name servers are searched in the
  2353.         order specified in the database.
  2354.         Example:
  2355.  
  2356.         NS 130.233.224.1 ; santra.hut.fi
  2357.  
  2358.         Note that the symbolic name is after the ';' character,which
  2359.         marks the start of an end of line comment.
  2360.  
  2361.     DO=DOMAIN hdomain namei  Add a domain name entry to the network
  2362.         database.  The hdomain namei is the part following the first '.'
  2363.         in the official host name.  The domain entries specify the
  2364.         domains from which a host name is searched.  The search is done
  2365.         in the order of the entries added to the network database.
  2366.         Example:
  2367.  
  2368.         DOMAIN cs.hut.fi
  2369.  
  2370.  
  2371. QUERY hvariable namei [: :]:Get the value of the variable.  Many variables
  2372.     have a two-level hierarchical structure (especially for variables
  2373.     related to the statistics) in which both the name of the table and
  2374.     the name of the variable itself must be supplied.
  2375.  
  2376.     Values for many variables can be queried with one command by putting
  2377.     names of the variables in a row.
  2378.  
  2379.  
  2380. RESET Reread the network database file AmiTCP:db/netdb.
  2381.  
  2382.  
  2383. SET hvariable namei hvariable valuei [::]:  Set the value of a variable.
  2384.     Name of the variable is given as with QUERY and the value is given
  2385.     after the name.
  2386.  
  2387.     Multiple variables can be set with one command by supplying
  2388.     name-variable pairs.
  2389.  
  2390.     Note that some variables are read-only and others writeable only
  2391.     during configuration.
  2392.  
  2393.  
  2394.  
  2395. 2.5.2   Variables
  2396.  
  2397. Here is a complete list of all configuration and network statistic
  2398. variables.
  2399.  
  2400.  
  2401. 20    Section 2.5                  AmiTCP/IP                   System Manual
  2402.  
  2403.  
  2404.  
  2405. WITH Include a file with multiple settings.  (This pseudo variable is a
  2406.     extension to the SET command.)
  2407.  
  2408. ICMP Variables related to Internet Message Control Protocol.  Alias:  IC
  2409.  
  2410.  
  2411.     ERROR  Number ofcalls to icmp_error().  Alias:  E
  2412.  
  2413.     SHORTOLD  No error because old IP wastoo short.  Alias:  S
  2414.  
  2415.     ICMPOLD  No error because oldwas ICMP. Alias:  I
  2416.  
  2417.     CODE  ICMP code out of range.  Alias:  CO
  2418.  
  2419.     TOOSHORT  Packet too short.  Alias: T
  2420.  
  2421.     CHKSUM  Checksum error.  Alias:  CH
  2422.  
  2423.     LENGTH  Data length larger than packet.  Alias:  L
  2424.  
  2425.     RESPONSES  Number of responses.  Alias:  R
  2426.  
  2427.  
  2428. ICMPHIST ICMP packet send and reception history.  See page 24 for details
  2429.     on the output format.  Alias:  ICH
  2430.  
  2431. IP Variables related to Internet Protocol.
  2432.  
  2433.  
  2434.     TOTAL  Total number of packets.  Alias:  T
  2435.  
  2436.     CHKSUM  Checksum error.  Alias:  CH
  2437.  
  2438.     TOOSHORT  Packet too short.  Alias: TOOSH
  2439.  
  2440.     TOOSMALL  Not enough data.  Alias:  TOOSM
  2441.  
  2442.     HEADER  IP header length less than data size.  Alias:  H
  2443.  
  2444.     LENGTH  IP header length larger than packet.  Alias:  LE
  2445.  
  2446.     FRAGMENTS  Packet fragments received.  Alias:  FS
  2447.  
  2448.     FDROP  Fragmentsdropped (duplicates, out of space).  Alias:  FD
  2449.  
  2450.     FTIMEOUT  Fragments timed out.  Alias:  FT
  2451.  
  2452.     FORWARD  Packets forwarded.  Alias: FO
  2453.  
  2454.     FWDCANT  Packets received forunreachable destination.  Alias:  FW
  2455.  
  2456.     REDIRECTSENT  Packets forwarded on same net.  Alias:  RED
  2457.  
  2458.     NOPROTO  Unknown or unsupported protocol.  Alias:  N
  2459.  
  2460.     DELIVER  Packets consumed here.  Alias:  D
  2461.  
  2462.     LOCALOUT  Total IP packets generatedhere.  Alias:  LO
  2463.  
  2464.     ODROPPED  Lost packets due to nobufs,etc.  Alias:  OD
  2465.  
  2466.     REASSEMBLED  Total packets reassembled ok.  Alias:  REA
  2467.  
  2468.     FED Output packets fragmented ok.  Alias:  FE
  2469.  
  2470.     OFRAGMENTS  Output fragments created.  Alias:  OF
  2471.  
  2472.     FCANT  Don't fragment flag was set, etc.  Alias:  FC
  2473.  
  2474.  
  2475. TCP Variables related to Transmission Control Protocol.  Alias:  T
  2476.  
  2477.  
  2478.     CATTEM  Connections initiated. Alias:  CA
  2479.  
  2480.     ACCEPTS  Connections accepted.  Alias:  A
  2481.  
  2482.  
  2483. System Manual                   AmiTCP/IP                   Section 2.5    21
  2484.  
  2485.  
  2486.  
  2487.     CONNECT  Connections established.  Alias:  CO
  2488.  
  2489.     DROPS  Connections  dropped.  Alias:  DR
  2490.  
  2491.     CDROPS  Embryonic connections dropped.  Alias:  CD
  2492.  
  2493.     CLOSED  Connections closed (incl.  drops).  Alias:  CL
  2494.  
  2495.     SEGSTIMED  Segments where we tried to get rtt.  Alias:  SE
  2496.  
  2497.     RTTUPDATE  Times we succeed rtt.  Alias:  RTT
  2498.  
  2499.     DELACK  Delayed acknowledgments sent.  Alias:  DE
  2500.  
  2501.     TIMEODROP  Connection dropped in rxmt timeout.  Alias:  T
  2502.  
  2503.     REXMTT  Retransmit timeouts. Alias:  RE
  2504.  
  2505.     PERSIST  Persist timeouts.  Alias:  P
  2506.  
  2507.     KATIMEO  Keepalive timeouts.  Alias: KAT
  2508.  
  2509.     KAPROBE  Keepalive probes sent.  Alias:  KAP
  2510.  
  2511.     KADROPS  Connections dropped in keepalive.  Alias:  KAD
  2512.  
  2513.     STOTAL  Total packets sent.  Alias:  ST
  2514.  
  2515.     SPACK  Data packets sent.  Alias:  SP
  2516.  
  2517.     SBYTE  Data bytes sent.  Alias:  SB
  2518.  
  2519.     SREPACK  Data packets retransmitted.  Alias:  SREP
  2520.  
  2521.     SREBYTE  Data bytes retransmitted.  Alias:  SREB
  2522.  
  2523.     SACKS  Ack-onlypackets sent.  Alias:  SA
  2524.  
  2525.     SWPROBE  Window probes sent. Alias:  SWP
  2526.  
  2527.     SURGENT  Packets sent with URGonly.  Alias:  SU
  2528.  
  2529.     SWUPDATE  Window update-only packetssent.  Alias:  SWU
  2530.  
  2531.     SCTRL  Control (SYN_FIN_RST) packets sent.  Alias:  SC
  2532.  
  2533.     RTOTAL  Total packets received.  Alias:  RTO
  2534.  
  2535.     RPACK  Packets received in sequence.  Alias:  RPA
  2536.  
  2537.     RBYTE  Bytes received in sequence.  Alias:  RB
  2538.  
  2539.     RCHKSUM  Packets received withchecksum errors.  Alias:  RC
  2540.  
  2541.     ROFFSET  Packets received withbad offset.  Alias:  ROF
  2542.  
  2543.     RPSHORT  Packets received tooshort.  Alias:  RPS
  2544.  
  2545.     RDUPPACK  Duplicate-only packets received.  Alias:  RDUPP
  2546.  
  2547.     RDUPBYTE  Duplicate-only bytes received.  Alias:  RDUPB
  2548.  
  2549.     RPDUPDATA  Packets with some duplicate data. Alias:  RPDUPD
  2550.  
  2551.     RPDUPBYTE  Dup.  bytes in part-dup.  packets.  Alias:  RPDUPB
  2552.  
  2553.     ROOPACK  Out-of-order packetsreceived.  Alias:  ROOP
  2554.  
  2555.     ROOBYTE  Out-of-order bytes received.  Alias:  ROOB
  2556.  
  2557.     RPLATE  Packets with data after window.  Alias:  RPL
  2558.  
  2559.     RBLATE  Bytes receivedafter window.  Alias:  RBL
  2560.  
  2561.     RAFTER  Packets received after close.  Alias:  RAF
  2562.  
  2563.     RWPROBE  Received window probepackets.  Alias:  RWP
  2564.  
  2565.  
  2566. 22    Section 2.5                  AmiTCP/IP                   System Manual
  2567.  
  2568.  
  2569.  
  2570.     RDUPACK  Received duplicate acknowledgments.  Alias:  RDUPA
  2571.  
  2572.     RACKTOOM  Received acknowledgments for unsent data.  Alias:  RACKT
  2573.  
  2574.     RACKPACK  Received acknowledgment packets.  Alias:  RACKP
  2575.  
  2576.     RACKBYTE  Bytes acknowledged by received acknowledgments.  Alias:
  2577.         RACKB
  2578.  
  2579.     RWUPDATE  Received window update packets.  Alias:  RWU
  2580.  
  2581.  
  2582. UDP Variables related to User Datagram Protocol.  Alias:  U
  2583.  
  2584.  
  2585.     ITOTAL  Total input packets.  Alias:  I
  2586.  
  2587.     HEADSHORT  Packet shorter than header.  Alias:  H
  2588.  
  2589.     CHKSUM  Checksum error.  Alias:  C
  2590.  
  2591.     LENGTH  Data length larger than packet.  Alias:  L
  2592.  
  2593.     NOPORT  No socket on port.  Alias:  N
  2594.  
  2595.     BCNOPORT  No socket on port, arrivedas broadcast.  Alias:  B
  2596.  
  2597.     FULLSOC  Not delivered, inputsocket full.  Alias:  F
  2598.  
  2599.     MISPCB  Input packets missing pcb cache.  Alias:  M
  2600.  
  2601.     OTOTAL  Total output packets.  Alias:  O
  2602.  
  2603.  
  2604. CONNECTIONS  Returns a list ofall TCP and UDP connections, including
  2605.     server (listening) sockets.  See page 24 for the output format
  2606.     description.
  2607.  
  2608. MBUF_STAT Memory buffer statistics.  Alias:  MBS
  2609.  
  2610.  
  2611.     MBUFS  Total number of allocated memory buffers.  Alias:  M
  2612.  
  2613.     CLUSTERS  Total number of allocated memory buffer clusters.  Alias:
  2614.         CL
  2615.  
  2616.     CLFREE  Number of memory buffer clusters free.  Alias:  CLF
  2617.  
  2618.     MDROPS  Times failed tofind space.  Alias:  MD
  2619.  
  2620.     NWAITED  Times waited for space.  Alias:  NW
  2621.  
  2622.     NDRAINED  Times drained protocols forspace.  Alias:  ND
  2623.  
  2624.     TOTALMEMORYUSED  Total amount of memory used for the mbufs.  Alias:
  2625.         TMU
  2626.  
  2627.  
  2628. MBUF_TYPE_STATS Returns type specific statistics of mbuf allocations.  The
  2629.     last number is the total number of mbufs allocated.  Alias:  MBTS
  2630.  
  2631. MBUF_CONF Memory buffer configuration.  Alias:  MBC
  2632.  
  2633.  
  2634.     INITIAL  Number of mbuf chunksto allocate initially.  Alias:  I
  2635.  
  2636.     CHUNK  Number ofmbufs to allocate at a time.  Alias:  CH
  2637.  
  2638.     CLCHUNK  Number of clusters toallocate at a time.  Alias:  CL
  2639.  
  2640.     MAXMEM  Maximum memoryto use (in kilobytes).  Alias:  MM
  2641.  
  2642.     CLUSTERSIZE  Size of an mbuf cluster.  Alias:  CS
  2643.  
  2644.  
  2645. System Manual                   AmiTCP/IP                   Section 2.5    23
  2646.  
  2647.  
  2648.  
  2649. LOG Logging system configuration.
  2650.  
  2651.  
  2652.     COUNT  Number oflog messages to use.
  2653.  
  2654.     LEN Maximum length of a log message.
  2655.  
  2656.  
  2657. TASKNAME Name of AmiTCP/IP task.
  2658.  
  2659.  
  2660. NTHBASE Current AmiTCP/IP has nth bsdsocket.library base currently in
  2661.     memory.  Alias:  NTH
  2662.  
  2663.  
  2664. DEBUGSANA  Boolean to switch the SANA-II device interface debugging on and
  2665.  
  2666.     off3.  Alias:  DBSANA
  2667.  
  2668.  
  2669. DEBUGICMP  Boolean to switch the ICMP debugging on and off.  Alias:
  2670.     DBICMP
  2671.  
  2672.  
  2673. DEBUGIP Boolean telling whether IP should log debugging information.
  2674.     Alias:  DBIP
  2675.  
  2676.  
  2677. GATEWAY Boolean to switch gateway functionality on and off.  Alias:  GTW
  2678.  
  2679.  
  2680. IPSENDREDIRECTS  Boolean telling whether IP should send ICMP redirect
  2681.     messages.  Alias:  REDIR
  2682.  
  2683.  
  2684. USENAMESERVER  How to use name server.  Possible values are:
  2685.  
  2686.  
  2687.     NO Do not use name server at all.  Local database will be used
  2688.         instead.
  2689.  
  2690.     FIRST  Query thename servers first and if that fails, use local
  2691.         database.
  2692.  
  2693.     SECOND  First look up the local database, then, if that fails, query
  2694.         the name servers.
  2695.  
  2696.  
  2697.     Alias:  USENS
  2698.  
  2699.  
  2700. USELOOPBACK  If true use the local loop device for local traffic.  Alias:
  2701.     ULO
  2702.  
  2703.  
  2704. TCP_SENDSPACE  Default size of the sending socket buffer (TCP). Alias:
  2705.     TCPSND
  2706.  
  2707.  
  2708. TCP_RECVSPACE  Default size of the receiving socket buffer (TCP). Alias:
  2709.     TCPRCV
  2710.  
  2711.  
  2712. CONSOLENAME  Filename for thelog console.  Alias:  CON
  2713.  
  2714.  
  2715. LOGFILENAME  Filename for thelog file.  Alias:  LOGF
  2716.  
  2717.  
  2718. ________________________________
  2719.    3See page 24 for description about boolean variable.
  2720.  
  2721.  
  2722. 24    Section 2.5                  AmiTCP/IP                   System Manual
  2723.  
  2724.  
  2725.  
  2726. Boolean variables
  2727.  
  2728. The variables documented as boolean accept their values in various
  2729.  
  2730. formats.  Boolean false may be given asNO4 , FALSE, OFF or 0.  YES, TRUE,
  2731. ON and 1 are considered as boolean true.
  2732.    The firstalternatives are used on output.
  2733.  
  2734.  
  2735.  
  2736. CONNECTIONS output format
  2737.  
  2738. CONNECTIONS query returns its result ina format which has
  2739. space-separated fields, connection afterconnection (not sorted).  Format
  2740. is as follows:
  2741.  
  2742.      _____________________________________________________________________
  2743.      !_Field_length_!___Value_type____!Description_______________________!_
  2744.      !_______1_______!char_`t'_or_`u'_!t_for_TCP_connection,_u_for_UDP_!__
  2745.      !_______4_______!__4-char_hex____!Receive_queue_length_____________!_
  2746.      !_______4_______!__4-char_hex____!Send_queue_length________________!_
  2747.      !_______8_______!__8-char_hex____!Local_address_____________________!_
  2748.      !_______4_______!__4-char_hex____!Local_port_number________________!_
  2749.      !_______8_______!__8-char_hex____!Foreign_address___________________!_
  2750.      !_______4_______!__4-char_hex____!Foreign_port_number______________!_
  2751.      !_______1_______!__1-char_hex____!State_of_connection______________!_
  2752.  
  2753.  
  2754.    The hexadecimal values are zero padded from left to their full length.
  2755. Last item presents the state of the TCPfinite state machine.  Possible
  2756. values for it are:
  2757.  
  2758.               ____________________________________________________
  2759.               !_Value_!State_of_TCP_FSM________________________!__
  2760.               !___0___!Closed___________________________________!_
  2761.               !___1___!Listening_for_connection________________!__
  2762.               !___2___!Active,_has_sent_SYN____________________!__
  2763.               !___3___!Has_send_and_received_SYN______________!___
  2764.               !___4___!Established______________________________!_
  2765.               !___5___!Received_FIN,_waiting_forclose_________!___
  2766.               !___6___!Has_been_closed,_sent_FIN______________!___
  2767.               !___7___!Closed_exchanged_FIN;_awaiting_FIN_ACK_!___
  2768.               !___8___!Had_FIN_and_close;_awaiting_FIN_ACK_____!__
  2769.               !___9___!Has_been_closed,_FIN_is_acknowledged___!___
  2770.               !___A___!Is_in_2*msl_quiet_wait_after_close______!__
  2771.  
  2772.  
  2773.  
  2774. ICMPHIST output format
  2775.  
  2776. ICMPHIST query returns the ICMP historytable entries on one line
  2777. separated by spaces.  Outhistory is returned first beginning from the
  2778. entry 0.  Both tables contains 19 entries for differentICMP messages.
  2779. Note that all message types are not in use.   Message types are as
  2780. follows:________________________
  2781.  
  2782.    4Upper case keywords are used here for clarity only.  Lower case (or
  2783.  
  2784. mixed case) keywords are accepted as well.
  2785.  
  2786.  
  2787. System Manual                   AmiTCP/IP                   Section 2.5    25
  2788.  
  2789.  
  2790.  
  2791.                         ________________________________
  2792.                         !__0_e!cho_reply_______________!_
  2793.                         !__1_n!ot_used_________________!_
  2794.                         !__2_n!ot_used_________________!_
  2795.                         !__3_D!estination_unreachable_!_
  2796.                         !__4_P!acket_lost,_slow_down__!_
  2797.                         !__5_S!horter_route____________!_
  2798.                         !__6_n!ot_used_________________!_
  2799.                         !__7_n!ot_used_________________!_
  2800.                         !__8_E!cho_service_____________!_
  2801.                         !__9_n!ot_used_________________!_
  2802.                         !_10_!not_used_________________!_
  2803.                         !_11_!Time_exceeded____________!_
  2804.                         !_12_!IP_header_bad____________!_
  2805.                         !_13_!Timestamp_request________!_
  2806.                         !_14_!Timestamp_reply__________!_
  2807.                         !_15_!Information_request_____!_
  2808.                         !_16_!Information_reply________!_
  2809.                         !_17_!Address_mask_request____!_
  2810.                         !_18_!Address_mask_reply______!_
  2811.  
  2812.  
  2813. 26    Section 2.5                  AmiTCP/IP                   System Manual
  2814.  
  2815.  
  2816.  
  2817.  
  2818.  
  2819. Chapter 3
  2820.  
  2821.  
  2822.  
  2823. Programmer's  Manual
  2824.  
  2825.  
  2826.  
  2827. This chapter provides an in depth description of the AmiTCP/IP
  2828. application programming interface.  Following sectionsintroduce the
  2829. socket model of communication (3.1) andthe bsdsocket.library function
  2830. calls implementing the socket abstraction.   Some useful supporting
  2831. routines are described in section 3.2.  The client/server model is
  2832. introduced in section 3.3.  Some more advanced topics are discussed in
  2833. section 3.4.  Section 3.5 summarizes the small differences between
  2834. AmiTCP/IP and 4.3BSD socket APIs.  The full function reference of the
  2835. AmiTCP/IP API functions is in appendix Bstarting from page 128.
  2836.    The textin sections 3.1 -- 3.4 is based on the [Leffler et al 1991a ].
  2837.  
  2838.  
  2839.  
  2840. 3.1     Socket Concepts
  2841.  
  2842.  
  2843. The basic building block for communication is the socket.  A socket is an
  2844. endpoint of communication to which a name may be bound.  Each socket in
  2845. use has a type and one or more associated processes.  Sockets exist
  2846. within communication domains.  A communication domain is an abstraction
  2847. introduced to bundle common properties of processes communicating through
  2848. sockets.  One such property is the scheme used to name sockets.  Sockets
  2849.  
  2850. normally exchange data only with socketsin the same domain1.   The
  2851. AmiTCP/IP system supports currently onlyone communication domain:  the
  2852. Internet domain, which is used by processes which communicate using the
  2853. the DARPA standard communication protocols.   The underlying communication
  2854. facilities provided by the domains havea significant influence on the internal
  2855. system implementation as well as the interface to socket facilities available
  2856. to a user.
  2857.  
  2858.  
  2859.  
  2860. 3.1.1   Socket  Types
  2861.  
  2862. Sockets are typed according to the communication properties visible to a
  2863. user.  Processes are presumed to communicate only between sockets of the
  2864. same type, although there is nothing that prevents communication between
  2865. ________________________________
  2866.    1It may be possible to cross domain boundaries, but only if some
  2867.  
  2868. translation process is performed.
  2869.  
  2870.  
  2871.  
  2872.                                       27
  2873.  
  2874.  
  2875. 28    Section 3.1                  AmiTCP/IP                   System Manual
  2876.  
  2877.  
  2878.  
  2879. sockets of different types should the underlying communication protocols
  2880. support this.
  2881.    Three types of sockets currently are available to a user.  A stream
  2882. socket provides for the bidirectional, reliable, sequenced, and
  2883. unduplicated flow of data without recordboundaries.   Aside from the
  2884. bidirectionality of data flow, a pair ofconnected stream sockets
  2885.  
  2886. provides an interface nearly identical to that of pipes.2
  2887.    A datagram socket supports bidirectional flow of data which is not
  2888. promised to be sequenced, reliable, or unduplicated.  That is, a process
  2889. receiving messages on a datagram socketmay find messages duplicated,
  2890. and, possibly, in an order different from the order in which it was sent.
  2891. An important characteristic of a datagram socket is that record
  2892. boundaries in data are preserved.  Datagram sockets closely model the
  2893. facilities found in many contemporary packet switched networks such as
  2894. the Ethernet.
  2895.    A raw socket provides users access to the underlying communication
  2896. protocols which support socket abstractions.   These sockets are normally
  2897. datagram oriented, though their exact characteristics are dependent on
  2898. the interface provided by the protocol.  Raw sockets are not intended for
  2899. the general user; they have been provided mainly for those interested in
  2900. developing new communication protocols,or for gaining access to some of
  2901. the more esoteric facilities of an existing protocol.  The use of raw
  2902. sockets is considered in section 3.4.
  2903.    Another potential socket type which has interesting properties is the
  2904. reliably delivered message socket.  The reliably delivered message socket
  2905. has similar properties to a datagram socket, but with reliable delivery.
  2906. There is currently no support for this type of socket, but a reliably
  2907. delivered message protocol similar to Xerox's Packet Exchange Protocol
  2908. (PEX) may be simulated at the user level.   More information on this topic
  2909. can be found in section 3.4.
  2910.  
  2911.  
  2912.  
  2913. 3.1.2   Using The Socket Library
  2914.  
  2915. As any other Amiga shared library the bsdsocket.library must be opened to
  2916. be able to access the functions in the library.   Thiscan be done with
  2917. Exec's OpenLibrary() call.  The call returns a librarybase pointer which
  2918. is task specfic, which means that each separate task (or process) must
  2919. open the library itself.  This is because the AmiTCP/IPstores task
  2920. specific information to the library basestructure.
  2921.    The library base pointer returned by the OpenLibrary() must be stored
  2922. in to a variable accessable from the program (usually global) named
  2923. SocketBase.  Example of opening the library follows:
  2924.  
  2925.  
  2926. #include <exec/libraries.h>
  2927.  ...
  2928. struct Library *SocketBase = NULL;
  2929.  ...
  2930.     if ((SocketBase = OpenLibrary("bsdsocket.library", 2)) == NULL) -
  2931. ________________________________
  2932.    2In the UNIX systems pipes havebeen implemented internally as simply
  2933.  
  2934. a pair of connected stream sockets.
  2935.  
  2936.  
  2937. System Manual                   AmiTCP/IP                   Section 3.1    29
  2938.  
  2939.  
  2940.  
  2941.          /* couldnot open the library */
  2942.           ...
  2943.     "
  2944.     else -
  2945.          /* SocketBase now points to socket base of this task */
  2946.           ...
  2947.     "
  2948.  
  2949.  
  2950.    Note thatthe library version argument of the OpenLibrary() call is
  2951. given as 2, which means that at least version 2 is needed.  This is the
  2952. minimum version which should be requested, since the version 1 is
  2953. incompatible with the version 2 and up.  If the application uses features
  2954. defined for some specific version (and up), a later version number should
  2955. be specified.
  2956.    After theapplication is done with sockets the library must be closed.
  2957. This is done with CloseLibrary() as follows:
  2958.  
  2959.  
  2960.     if (SocketBase) -
  2961.          CloseLibrary(SocketBase);
  2962.          SocketBase = NULL;
  2963.     "
  2964.  
  2965.  
  2966.    Note thatif the application in question is multithreaded, each task
  2967. (or process) need to open/close its ownlibrary base.  The base opened by
  2968. the net.lib may be used by the originaltask only!
  2969.    Many programs expect the error values of the socket calls to be placed
  2970. in a global variable named errno.  By default a sharedlibrary cannot
  2971. know the address (nor size) of the applications variables, however.
  2972. There are two remedies to this:
  2973.  
  2974.  
  2975.  1. Use function Errno() to retrieve the error value, or
  2976.  
  2977.  
  2978.  2. Tell the address and the size of the errno variable to the AmiTCP/IP
  2979.     by using the SetErrnoPtr() call.
  2980.  
  2981.  
  2982.    The latter method requires only one additional function call to the
  2983. startup of the application, and is thusthe preferred method.  The call
  2984. may look like:
  2985.  
  2986.  
  2987. #include <errno.h>
  2988. #include <sys/socket.h>
  2989.  ...
  2990.     SetErrnoPtr(&errno, sizeof(errno));
  2991.  
  2992.  
  2993.    All thisis done automatically for the application if it is linked with
  2994.  
  2995. the net.lib3.  See section 3.1.3 for more information about the net.lib
  2996. and about compiling and linking the applications.
  2997. ________________________________
  2998.    3The net.lib is compiler dependent and is currently defined for SASC 6
  2999.  
  3000. only.  The actual name of the library varies and depends on the compiler
  3001. options used.
  3002.  
  3003.  
  3004. 30    Section 3.1                  AmiTCP/IP                   System Manual
  3005.  
  3006.  
  3007.  
  3008. 3.1.3   Compiling and Linking The Applications
  3009.  
  3010. AmiTCP/IP provides standard BSD Unix header files to be used by the
  3011. applications.  Normally they are installed to a directory which is
  3012. assigned to a name NETINCLUDE: (see section 1.1).   This means that you
  3013. should add the NETINCLUDE: to the compilers search path for include
  3014. files.
  3015.    The include files are decribed briefly in the following subsection:
  3016.  
  3017.  
  3018.  
  3019. The NETINCLUDE Header Files
  3020.  
  3021. bsdsocket.h  This file includes compiler specific prototypes and inline
  3022.     functions for bsdsocket.library.  Currently supported compilers are
  3023.     GCC and SAS C version 6.  The prototypes for the library functions
  3024.     are automatically included by the include files when appropriate,
  3025.     i.e.  when the prototypes where declared in the original BSD
  3026.     includes.  Thus the bsdsocket.h is included by sys/socket.h, netdb.h
  3027.     and arpa/inet.h.
  3028.  
  3029.     For other compilers only C prototypes are included, so stub routines
  3030.     should be used to call the functions.
  3031.  
  3032. errno.h Replacement for the errno.h included in the standard C-compiler
  3033.     headers.  This includes the file sys/errno.h, which defines symbolic
  3034.     constants for the error values returned by socket library calls.
  3035.     This file is BSD compatible and may well replace file provided by the
  3036.     SAS/C 6.
  3037.  
  3038. netdb.h Contains definitions and prototypes for the network database
  3039.     functions, such as the gethostbyname().
  3040.  
  3041.  Standard BSD System Headers
  3042.  
  3043.  
  3044.     sys/errno.h  Error code definitions for system functions.
  3045.  
  3046.     sys/ioctl.h  Definitions for socket IO control.
  3047.  
  3048.     sys/param.h  General machine independent parameter definitions.
  3049.  
  3050.     sys/socket.h  Definitions related to sockets:  types, address
  3051.         families, options and prototypes.
  3052.  
  3053.     sys/syslog.h  Definations for system logging facilities.
  3054.  
  3055.     sys/time.h  Definition of structure timeval.
  3056.  
  3057.     sys/types.h  Common C type definitions and file descriptorset macros
  3058.         for select().
  3059.  
  3060.  
  3061.  Internet Related Headers
  3062.  
  3063.  
  3064.     arpa/inet.h  Inet library function prototypes (inet_addr() etc.).
  3065.         Included for compatibility and only includes other include files.
  3066.  
  3067.     netinet/in.h  Protocol numbers, port conventions, inet address
  3068.         definitions.
  3069.  
  3070.     netinet/in_systm.h  Some network byte order type definitions.
  3071.  
  3072.     netinet/ip.h  IP packet header, packet options, timestamp.
  3073.  
  3074.  
  3075. System Manual                   AmiTCP/IP                   Section 3.1    31
  3076.  
  3077.  
  3078.  
  3079.     netinet/ip_icmp.h  ICMP packet structure.
  3080.  
  3081.     netinet/ip_var.h  Defines IP statistics, external IP packet header,
  3082.         reassemble queues structures.
  3083.  
  3084.     netinet/tcp.h  Defines the TCP packet structure.
  3085.  
  3086.     netinet/udp.h  Defines the UDP packet structure.
  3087.  
  3088.  
  3089.  Network Related Headers
  3090.  
  3091.     net/if.h  Defines the interface for network adapter drivers.
  3092.  
  3093.     net/if_arp.h  General protocol independent ARP structures.
  3094.  
  3095.     net/route.h  Routing ioctl definitions.
  3096.  
  3097.     net/sana2errno.h  Sana-II related error definitions.
  3098.  
  3099.     net/sana2tags.h  Tag definitions for configuring the Sana-II software
  3100.         network interface.
  3101.  
  3102.  Inetd Support
  3103.  
  3104.     inetd.h  Internet daemon interface definitions.
  3105.  
  3106.     inetdlib.h  Internet daemon library definitions.
  3107.  
  3108.  Prototypes
  3109.  
  3110.     clib/socket_inlines.h   Inline function definitions for those BSD
  3111.         socket API functions, which are not implemented strictly like
  3112.         originals by bsdsocket.library.
  3113.  
  3114.     clib/socket_protos.h  bsdsocket.library function call prototypes.
  3115.  
  3116.  SAS/C Pragmas
  3117.  
  3118.     pragmas/socket_pragmas.h   SAS/C pragma library calls for
  3119.         bsdsocket.library.
  3120.  
  3121.  SAS/C Proto -file
  3122.  
  3123.     proto/socket.h  Include file normally included by the SAS/C programs.
  3124.         Defines the socket base variable and includes the files
  3125.         clib/socket_protos.h and pragmas/socket_pragmas.h.
  3126.  
  3127.  GCC Inline Functions
  3128.  
  3129.     inline/socket.h  GCC inline functions for the bsdsocket.library
  3130.         functions.
  3131.  
  3132.  Function Description File
  3133.  
  3134.     fd/socket_lib.fd  Standard fd-file which specifies in which registers
  3135.         the arguments to the bsdsocket.library functions are passed.
  3136.         This file can be used to obtain information needed to call the
  3137.         bsdsocket.library functions by the assembler programs.
  3138.  
  3139.  Sana-II Header Files
  3140.  
  3141.     devices/sana2.h  Definitions for the Sana-II network device driver
  3142.         interface.
  3143.  
  3144.  
  3145. 32    Section 3.1                  AmiTCP/IP                   System Manual
  3146.  
  3147.  
  3148.  
  3149.     devices/sana2specialstats.h   Special statistics definitions for the
  3150.         Sana-II.
  3151.  
  3152.  Miscellaneous
  3153.  
  3154.     charread.h  Macro package to do buffered byte-by-byte reading from a
  3155.         socket.
  3156.  
  3157.     lineread.h  Definitions for buffered line orientedreading from a
  3158.         socket.
  3159.  
  3160.  
  3161.  
  3162. Linking With net.lib
  3163.  
  3164. AmiTCP/IP distribution includes a link library named net.lib to be used
  3165. by the applications.  It is normally located in the directory which has
  3166. an assigned name NETLIB:.
  3167.    The library contains compiler dependent code which makes the library
  3168.  
  3169. itself compiler dependent.  Currently only SASC version6 is supported4.
  3170.    net.lib features automatic initialization and termination functions
  3171. which open and close the bsdsocket.library for the application.  Using
  3172. this feature it is possible to compile some typical BSD Unix socket based
  3173. applications with AmiTCP/IP without anymodifications to the original
  3174. source code.  Note that this base may be used by the process starting the
  3175. program, i.e.  the one that executes themain().  This applies to the
  3176. included utility functions which call the socket library, too.
  3177.    The library also defines new array of error names to be used by
  3178. perror() library function.  This is done because the error name array
  3179. normally used by Amiga C compilers doesnot contain enough error entries,
  3180. resulting perror() to print "Unknown error code" if some socket error is
  3181. passed.  Note that for perror() to work the error valuemust be placed
  3182. into the global errno variable.  This is accomplished by the
  3183. SetErrnoPrt() call made in the automaticinitialization function.
  3184.    For the library functions to take effect, the library must be specified
  3185. before the C compiler own libraries in the link command line.
  3186.  
  3187.  
  3188.  
  3189. 3.1.4   Socket  Creation
  3190.  
  3191. To create a socket the socket() system call is used:
  3192.  
  3193.     s = socket(domain, type, protocol);
  3194.  
  3195. This call requests that the system create a socket in the specified
  3196. domain and of the specified type.  A particular protocol may also be
  3197. requested.  If the protocol is left unspecified (a value of 0), the
  3198. system will select an appropriate protocol from those protocols which
  3199. comprise the communication domain and which may be used to support the
  3200. requested socket type.  The user is returned a descriptor (a small
  3201. integer number) which may be used in later system calls which operate on
  3202. sockets.  The domain is specified as one of the manifest constants
  3203. ________________________________
  3204.    4But since the source for the library is provided, it can be used with
  3205.  
  3206. any C compiler.
  3207.  
  3208.  
  3209. System Manual                   AmiTCP/IP                   Section 3.1    33
  3210.  
  3211.  
  3212.  
  3213. defined in the file sys/socket.h.  For the Internet domain the constant
  3214.  
  3215. is AF_INET5. The socket types are also defined in this file and one of
  3216. SOCK_STREAM, SOCK_DGRAM or SOCK_RAW mustbe specified.  To create a stream socket
  3217. in the Internet domain the following call might be used:
  3218.  
  3219.     s = socket(AF_INET, SOCK_STREAM, 0);
  3220.  
  3221. This call would result in a stream socket being created with the TCP
  3222. protocol providing the underlying communication support.  To create a
  3223. datagram socket the call might be:
  3224.  
  3225.     s = socket(AF_INET, SOCK_DGRAM, 0);
  3226.  
  3227.    The default protocol (used when the protocol argument to the socket()
  3228. call is 0) should be correct for most every situation.  However, it is
  3229. possible to specify a protocol other than the default; this will be
  3230. covered in section 3.4.
  3231.    There areseveral reasons a socket() call may fail.  Aside from the
  3232. rare occurrence of lack of memory (ENOBUFS), a socket request may fail
  3233. due to a request for an unknown protocol(EPROTONOSUPPORT), or a request
  3234. for a type of socket for which there isno supporting protocol
  3235. (EPROTOTYPE).
  3236.  
  3237.  
  3238.  
  3239. 3.1.5   Binding Local Names
  3240.  
  3241. A socket is created without a name.  Until a name is bound to a socket,
  3242. processes have no way to reference it and, consequently, no messages may
  3243. be received on it.  Communicating processes are bound by an association.
  3244. In the Internet domain, an association is composed of local and foreign
  3245. addresses, and local and foreign ports,In most domains, associations
  3246. must be unique.  In the Internet domain there may neverbe duplicate
  3247. <protocol, local address, local port, foreign address, foreign port>
  3248. tuples.
  3249.    The bind() system call allows a process to specify half of an
  3250. association, <local address, local port>, while the connect() and
  3251. accept() calls are used to complete a socket's association.
  3252.    In the Internet domain, binding names to sockets can be fairly complex.
  3253. Fortunately, it is usually not necessaryto specifically bind an address
  3254. and port number to a socket, because theconnect() and send() calls will
  3255. automatically bind an appropriate address if they are used with an
  3256. unbound socket.
  3257.    The bind() system call is used as follows:
  3258.  
  3259.     bind(s, name, namelen);
  3260.  
  3261. The bound name is a variable length bytestring which is interpreted by
  3262. the supporting protocol(s).  Its interpretation may vary from
  3263. communication domain to communication domain (this is one of the
  3264. properties which comprise the domain).  As mentioned, in the Internet
  3265. domain names contain an Internet addressand port number.
  3266.    In binding an Internet address things are a little complicated:
  3267. ________________________________
  3268.    5The manifest constants are named AF _whatever as they indicate the
  3269.  
  3270. ``address format'' to use in interpreting names.
  3271.  
  3272.  
  3273. 34    Section 3.1                  AmiTCP/IP                   System Manual
  3274.  
  3275.  
  3276.  
  3277.     #include <sys/types.h>
  3278.     #include <netinet/in.h>
  3279.      ...
  3280.     struct sockaddr_in sin;
  3281.      ...
  3282.     bind(s, (struct sockaddr *) &sin, sizeof (sin));
  3283.  
  3284. The selection of what to place in the address sin requires some
  3285. discussion.  We will come back to the problem of formulating Internet
  3286. addresses in section 3.2 when the library routines used in name
  3287. resolution are discussed.
  3288.  
  3289.  
  3290.  
  3291. 3.1.6   Connection Establishment
  3292.  
  3293. Connection establishment is asymmetric,with one process a ``client'' and
  3294. the other a ``server''.  The server, when willing to offer its advertised
  3295. services, binds a socket to a well--known address associated with the
  3296. service and then passively ``listens'' on its socket.  It is then
  3297. possible for an unrelated process to rendezvous with the server.  The
  3298. client requests services from the serverby initiating a ``connection''
  3299. to the server's socket.  On the client side the connect() call is used to
  3300. initiate a connection.  Using the Internet domain, thismight apper as:
  3301.  
  3302.     struct sockaddr_in server;
  3303.      ...
  3304.     connect(s, (struct sockaddr *)&server, sizeof (server));
  3305.  
  3306.    where server in the example above would contain Internet address and
  3307. port number of the server to which the client process wishes to speak.
  3308. If the client process's socket is unbound at the time of the connect
  3309. call, the system will automatically select and bind a name to the socket
  3310. if necessary.  This is the usual way that local addresses are bound to a
  3311. socket.
  3312.    An erroris returned if the connection was unsuccessful (any name
  3313. automatically bound by the system, however, remains).  Otherwise, the
  3314. socket is associated with the server anddata transfer may begin.  Some
  3315. of the more common errors returned whena connection attempt fails are:
  3316.  
  3317.  
  3318.  ETIMEDOUT After failing to establish a connection for a period of time,
  3319.     the system decided there was no point in retrying the connection
  3320.     attempt any more.  This usually occurs because the destination host
  3321.     is down, or because problems in the network resulted in transmissions
  3322.     being lost.
  3323.  
  3324.  ECONNREFUSED The host refusedservice for some reason.  This is usually
  3325.     due to a server process not being present at the requested name.
  3326.  
  3327.  ENETDOWN or EHOSTDOWN These operational errors are returned based on
  3328.     status information delivered to the client host by the underlying
  3329.     communication services.
  3330.  
  3331.  ENETUNREACH or EHOSTUNREACH These operational errors can occur either
  3332.     because the network or host is unknown (no route to the network or
  3333.  
  3334.  
  3335. System Manual                   AmiTCP/IP                   Section 3.1    35
  3336.  
  3337.  
  3338.  
  3339.     host is present), or because of status information returned by
  3340.     intermediate gateways or switching nodes.  Many times the status
  3341.     returned is not sufficient to distinguish a network being down from a
  3342.     host being down, in which case the system indicates the entire
  3343.     network is unreachable.
  3344.  
  3345.  
  3346.    For the server to receive a client's connection it must perform two
  3347. steps after binding its socket.  The first is to indicate a willingness
  3348. to listen for incoming connection requests:
  3349.  
  3350.  
  3351.     listen(s, 5);
  3352.  
  3353.  
  3354. The second parameter to the listen() call specifies the maximum number of
  3355. outstanding connections which may be queued awaiting acceptance by the
  3356. server process; this number may be limited by the system.  Should a
  3357. connection be requested while the queueis full, the connection will not
  3358. be refused, but rather the individual messages which comprise the request
  3359. will be ignored.  This gives a harried server time to make room in its
  3360. pending connection queue while the client retries the connection request.
  3361. Had the connection been returned with the ECONNREFUSED error, the client
  3362. would be unable to tell if the server was up or not.  As it is now it is
  3363. still possible to get the ETIMEDOUT error back, though this is unlikely.
  3364. The backlog figure supplied with the listen call is currently limited by the
  3365. system to a maximum of 5 pending connections on any one queue.  This avoids
  3366. the problem of processes hogging systemresources by setting an infinite backlog,
  3367. then ignoring all connection requests.
  3368.    With a socket marked as listening, a server may accept a connection:
  3369.  
  3370.  
  3371.     struct sockaddr_in from;
  3372.      ...
  3373.     fromlen = sizeof (from);
  3374.     newsock = accept(s, (struct sockaddr *)&from, &fromlen);
  3375.  
  3376.  
  3377. A new descriptor is returned on receiptof a connection (along with a new
  3378. socket).  If the server wishes to find out who its client is, it may
  3379. supply a buffer for the client socket'sname.   The value--result
  3380. parameter fromlen is initialized by theserver to indicate how much space
  3381. is associated with from, then modified on return to reflect the true size
  3382. of the name.  If the client's name is not of interest,the second
  3383. parameter may be a NULL pointer.
  3384.    accept()normally blocks.  That is, accept() will not return until a
  3385.  
  3386. connection is available or the system call is interrupted by a signal6 to
  3387. the process.  Further, there is no way for a process toindicate it will
  3388. accept connections from only a specificindividual, or individuals.  It
  3389. is up to the user process to consider who the connection is from and
  3390. close down the connection if it does notwish to speak to the process.
  3391. If the server process wants to accept connections on more than one
  3392. socket, or wants to avoid blocking on the accept call, there are
  3393. alternatives; they will be considered insection 3.4.
  3394. ________________________________
  3395.    6By default, the CTRL-C signalinterrupts the system calls, but the
  3396.  
  3397. application may change this, however.
  3398.  
  3399.  
  3400. 36    Section 3.1                  AmiTCP/IP                   System Manual
  3401.  
  3402.  
  3403.  
  3404. 3.1.7   Data  Transfer
  3405.  
  3406.  
  3407. With a connection established, data maybegin to flow.  To send and
  3408. receive data there are a number of possible calls.   With the peer entity
  3409. at each end of a connection anchored, auser can send or receive a
  3410. message without specifying the peer.  The calls send()and recv() may be
  3411. used:
  3412.  
  3413.  
  3414.     send(s, buf, sizeof (buf), flags);
  3415.     recv(s, buf, sizeof (buf), flags);
  3416.  
  3417.  
  3418. While send() and recv() are virtually identical to the standard I/O
  3419. routines, the extra flags argument is important.   Theflags, defined in
  3420. sys/socket.h, may be specified as a non--zero value if one or more of the
  3421. following is required:
  3422.  
  3423.  
  3424.  MSG_OOB Send/receive out of band data.
  3425.  
  3426.  
  3427.  MSG_PEEK Lookat data without reading.
  3428.  
  3429.  
  3430.  MSG_DONTROUTESend data without routing packets.
  3431.  
  3432.  
  3433.    Out of band data is a notion specific to stream sockets, and one which
  3434. we will not immediately consider.  The option to have data sent without
  3435. routing applied to the outgoing packetsis currently used only by the
  3436. routing table management process, and isunlikely to be of interest to
  3437. the casual user.  The ability to preview data is, however, of interest.
  3438. When MSG_PEEK is specified with a recv() call, any data present is
  3439. returned to the user, but treated as still ``unread''.  That is, the next
  3440. recv() call applied to the socket will return the data previously
  3441. previewed.
  3442.  
  3443.  
  3444.  
  3445. 3.1.8   Discarding Sockets
  3446.  
  3447.  
  3448. Once a socket is no longer of interest,it may be discarded by applying a
  3449. CloseSocket() to the descriptor,
  3450.  
  3451.  
  3452.     CloseSocket(s);
  3453.  
  3454.  
  3455. If data is associated with a socket which promises reliable delivery
  3456. (e.g.  a stream socket) when a close takes place, the system will
  3457. continue to attempt to transfer the data.   However, after a fairly long
  3458. period of time, if the data is still undelivered, it will be discarded.
  3459. Should a user have no use for any pending data, it may perform a
  3460. shutdown() on the socket prior to closing it.   This call is of the form:
  3461.  
  3462.  
  3463.     shutdown(s, how);
  3464.  
  3465.  
  3466. where how is 0 if the user is no longerinterested in reading data, 1 if
  3467. no more data will be sent, or 2 if no data is to be sent or received.
  3468.  
  3469.  
  3470. System Manual                   AmiTCP/IP                   Section 3.1    37
  3471.  
  3472.  
  3473.  
  3474. 3.1.9   Connectionless Sockets
  3475.  
  3476. To this point we have been concerned mostly with sockets which follow a
  3477. connection oriented model.  However, there is also support for
  3478. connectionless interactions typical of the datagram facilities found in
  3479. contemporary packet switched networks.  A datagram socket provides a
  3480. symmetric interface to data exchange.  While processesare still likely
  3481. to be client and server, there is no requirement for connection
  3482. establishment.  Instead, each message includes the destination address.
  3483.    Datagramsockets are created as before.  If a particular local address
  3484. is needed, the bind operation must precede the first data transmission.
  3485. Otherwise, the system will set the localaddress and/or port when data is
  3486. first sent.  To send data, the sendto() call is used,
  3487.  
  3488.     sendto(s, buf, buflen, flags, (struct sockaddr *)&to, tolen);
  3489.  
  3490. The s, buf, buflen, and flags parametersare used as before.  The to and
  3491. tolen values are used to indicate the address of the intended recipient
  3492. of the message.  When using an unreliable datagram interface, it is
  3493. unlikely that any errors will be reported to the sender.  When
  3494. information is present locally to recognize a message that can not be
  3495. delivered (for instance when a network is unreachable), the call will
  3496. return -1 and the global value errno will contain an error number (See
  3497. section 3.1.2 for discussion about errno).
  3498.    To receive messages on an unconnected datagram socket, the recvfrom()
  3499. call is provided:
  3500.  
  3501.     recvfrom(s, buf, buflen, flags, (struct sockaddr *)&from, &fromlen);
  3502.  
  3503. Once again, the fromlen parameter is handled in a value--result fashion,
  3504. initially containing the size of the from buffer, and modified on return
  3505. to indicate the actual size of the address from which the datagram was
  3506. received.
  3507.    In addition to the two calls mentioned above, datagram sockets may also
  3508. use the connect() call to associate a socket with a specific destination
  3509. address.  In this case, any data sent on the socket will automatically be
  3510. addressed to the connected peer, and only data received from that peer
  3511. will be delivered to the user.  Only one connected address is permitted
  3512. for each socket at one time; a second connect() will change the
  3513. destination address, and a connect() toa null address (family AF_UNSPEC)
  3514. will disconnect.  Connect requests on datagram socketsreturn
  3515. immediately, as this simply results in the system recording the peer's
  3516. address (as compared to a stream socket,where a connect request
  3517. initiates establishment of an end to endconnection).  accept() and listen()
  3518. are not used with datagram sockets.
  3519.    While a datagram socket is connected, errors from recent send() calls
  3520. may be returned asynchronously.  These errors may be reported on
  3521. subsequent operations on the socket, ora special socket option used with
  3522. getsockopt(), SO_ERROR,may be used to interrogate the error status.  A
  3523. select() for reading or writing will return true when an error indication
  3524. has been received.  The next operation will return theerror, and the
  3525. error status is cleared.  Other of the less important details of datagram
  3526. sockets are described in section 3.4.
  3527.  
  3528.  
  3529. 38    Section 3.1                  AmiTCP/IP                   System Manual
  3530.  
  3531.  
  3532.  
  3533. 3.1.10   Input/Output  Multiplexing
  3534.  
  3535. One last facility often used in developing applications is the ability to
  3536. multiplex i/o requests among multiple sockets.   This is done using the
  3537. select() call.  The select() call provided by AmiTCP/IPis actually a
  3538. compile time inline function (or normalstub with compilers without
  3539. inline facility) which calls the WaitSelect().   The WaitSelect() call is
  3540. similar to the normal select() call, buthas one extra argument
  3541. specifying a pointer to a signal mask for the signals which should break
  3542. the selection (in addition to the timeouts and the break signal).  This
  3543. makes possible to use WaitSelect() instead of normal Wait() as a driver
  3544. for the applications event loop.  If the pointer is given as NULL the
  3545. functionality is as with BSD select().  The inline (orstub) function for select*
  3546.  *()
  3547. actually just calls the WaitSelect() with last argument as NULL.
  3548.    Here is abrief example of the usage of the WaitSelect():
  3549.  
  3550.  
  3551.     #include <sys/time.h>
  3552.     #include <sys/types.h>
  3553.      ...
  3554.  
  3555.  
  3556.     fd_set readmask, writemask, exceptmask;
  3557.     struct timeval timeout;
  3558.     ULONG signalmask;
  3559.      ...
  3560.     WaitSelect(nfds, &readmask, &writemask, &exceptmask, &timeout,
  3561.                 &signalmask);
  3562.  
  3563.  
  3564. WaitSelect() takes as arguments pointersto three sets, one for the set
  3565. of file descriptors for which the callerwishes to be able to read data
  3566. on, one for those descriptors to which data is to be written, and one for
  3567. which exceptional conditions are pending; out-of-band data is the only
  3568. exceptional condition currently implemented.   If the user is not
  3569. interested in certain conditions (i.e.,read, write, or exceptions), the
  3570. corresponding argument to the select() should be a NULL pointer.
  3571.    Each setis actually a structure containing an array of long integer
  3572. bit masks; the size of the array is setby the definition FD_SETSIZE. The
  3573. array is long enough to hold one bit foreach of FD_SETSIZE file
  3574. descriptors.
  3575.    The macros FD_SET(fd, &mask) and FD_CLR(fd, &mask) have been provided
  3576. for adding and removing file descriptorfd in the set mask.  The set
  3577. should be zeroed before use, and the macro FD_ZERO(&mask) has been
  3578. provided to clear the set mask.  The parameter nfds inthe select() call
  3579. specifies the range of file descriptors(i.e.   one plusthe value of the
  3580. largest descriptor) to be examined in aset.
  3581.    A timeoutvalue may be specified if the selection is not to last more
  3582. than a predetermined period of time.  If the fields intimeout are set to
  3583. 0, the selection takes the form of a poll, returning immediately.  If the
  3584.  
  3585. last parameter is a NULL pointer, the selection will block indefinitely7.
  3586. ________________________________
  3587.    7To be more specific, a returntakes place only when a descriptor is
  3588.  
  3589. selectable, or when a signal is receivedby the caller, interrupting the
  3590. system call.
  3591.  
  3592.  
  3593. System Manual                   AmiTCP/IP                   Section 3.1    39
  3594.  
  3595.  
  3596.  
  3597.    The lastargument is a pointer to the mask specifying signals for which
  3598. the WaitSelect() should break.  WaitSelect() normally returns the number
  3599. of file descriptors selected; if the WaitSelect() call returns due to the
  3600. timeout expiring, then the value 0 is returned.   If the WaitSelect()
  3601. terminates because of an error or interruption, a -1 is returned with the
  3602. error number in errno, and with the filedescriptor masks unchanged.  The
  3603. signal mask is altered on return to holdthe bits for the signals which
  3604. caused the break.
  3605.    Assuminga successful return, the three sets will indicate which file
  3606. descriptors are ready to be read from, written to, or have exceptional
  3607. conditions pending.  The status of a file descriptor ina select mask may
  3608. be tested with the FD_ISSET(fd, &mask) macro, which returns a non-zero
  3609. value if fd is a member of the set mask,and 0 if it is not.
  3610.    To determine if there are connections waiting on a socket to be used
  3611. with an accept() call, select() can be used, followed by a
  3612. FD_ISSET(fd, &mask) macro to check for read readiness on the appropriate
  3613. socket.  If FD_ISSET() returns a non-zero value, indicating permission to
  3614. read, then a connection is pending on the socket.
  3615.    As an example, to read data from two sockets, s1 and s2 as it is
  3616. available from each and with a one--second timeout, the following code
  3617. might be used:
  3618.  
  3619.  
  3620.     #include <sys/time.h>
  3621.     #include <sys/types.h>
  3622.     #include <sys/socket.h>
  3623.      ...
  3624.     fd_set read_template;
  3625.     struct timeval wait;
  3626.     int nb;
  3627.     int s1,s2;
  3628.     int maxfd;
  3629.      ...
  3630.     maxfd = s1 > s2 ? s1 : s2;
  3631.     for (;;) -
  3632.          wait.tv_sec = 1;         /* onesecond */
  3633.          wait.tv_usec = 0;
  3634.  
  3635.  
  3636.          FD_ZERO(&read_template);
  3637.  
  3638.  
  3639.          FD_SET(s1,  &read_template);
  3640.          FD_SET(s2,  &read_template);
  3641.  
  3642.  
  3643.          nb = select(maxfd, &read_template, NULL, NULL, &wait);
  3644.          if (nb <=0) -
  3645.              /* An error occurred during the select, or
  3646.                 the select timed out. */
  3647.          "
  3648.  
  3649.  
  3650.          if (FD_ISSET(s1, &read_template)) -
  3651.              /* Socket #1 is ready to be readfrom. */
  3652.          "
  3653.  
  3654.  
  3655.          if (FD_ISSET(s2, &read_template)) -
  3656.              /* Socket #2 is ready to be readfrom. */
  3657.  
  3658.  
  3659. 40    Section 3.2                  AmiTCP/IP                   System Manual
  3660.  
  3661.  
  3662.  
  3663.          "
  3664.     "
  3665.  
  3666.  
  3667.    Note theusage of the select(), which calls WaitSelect() with NULL
  3668. signal mask pointer.
  3669.    In 4.2BSD, the arguments to select() were pointers to integers instead
  3670. of pointers to fd_sets.  This type ofcall will still work as long as the
  3671. number of file descriptors being examined is less than the number of bits
  3672. in an integer; however, the methods illustrated above should be used in
  3673. all current programs.
  3674.    select()provides a synchronous multiplexing scheme.  Asynchronous
  3675. notification of output completion, inputavailability, and exceptional
  3676. conditions is possible through use of the SigIO and SigURG signals
  3677. described in section 3.4.
  3678.  
  3679.  
  3680.  
  3681. 3.2     Network  Library  Routines
  3682.  
  3683.  
  3684. The discussion in section 3.1 indicatedthe possible need to locate and
  3685. construct network addresses when using the interprocess communication
  3686. facilities in a distributed environment.  To aid in this task a number of
  3687. routines have been added to the Amiga shared socket library.  In this
  3688. section we will consider the routines provided to manipulate network
  3689. addresses.
  3690.    Locatinga service on a remote host requires many levels of mapping
  3691. before client and server may communicate.   A service is assigned a name
  3692. which is intended for human consumption;e.g.   ``the login server on host
  3693. monet''.  This name, and the name of the peer host, must then be
  3694. translated into network addresses whichare not necessarily suitable for
  3695. human consumption.  Finally, the address must then usedin locating a
  3696. physical location and route to the service.   The specifics of these three
  3697. mappings are likely to vary between network architectures.  For instance,
  3698. it is desirable for a network to not require hosts to be named in such a
  3699. way that their physical location is known by the client host.  Instead,
  3700. underlying services in the network may discover the actual location of the
  3701. host at the time a client host wishes tocommunicate.  This ability to have
  3702. hosts named in a location independent manner may induce overhead in connection
  3703. establishment, as a discovery process must take place, but allows a host to
  3704. be physically mobile without requiring it to notify its clientele of its current
  3705. location.
  3706.    Standardroutines are provided for:  mapping host names to network
  3707. addresses, network names to network numbers, protocol names to protocol
  3708. numbers, and service names to port numbers and the appropriate protocol
  3709. to use in communicating with the serverprocess.   The file netdb.h must
  3710. be included when using any of these routines.
  3711.  
  3712.  
  3713.  
  3714. 3.2.1   Host  Names
  3715.  
  3716.  
  3717. An Internet host name to address mappingis represented by the hostent
  3718. structure:
  3719.  
  3720.  
  3721. System Manual                   AmiTCP/IP                   Section 3.2    41
  3722.  
  3723.  
  3724.  
  3725.     struct  hostent -
  3726.          char    *h_name;         /* official name of host */
  3727.          char    **h_aliases;     /* alias list */
  3728.          int     h_addrtype;      /* host address type (e.g., AF_INET) */
  3729.          int     h_length;       /* length of address */
  3730.          char    **h_addr_list;  /* list of addresses, nullterminated */
  3731.     ";
  3732.  
  3733.  
  3734.     #define h_addr  h_addr_list[0]  /* first address, network byte order */
  3735.  
  3736.  
  3737.    The routine gethostbyname() takes an Internet host name and returns a
  3738. hostent structure, while the routine gethostbyaddr() maps Internet host
  3739. addresses into a hostent structure.
  3740.    The official name of the host and its public aliases are returned by
  3741. these routines, along with the address type (family) and a null
  3742. terminated list of variable length addresses.   This list of addresses is
  3743. required because it is possible for a host to have many addresses, all
  3744. having the same name.  The h_addr definition is provided for backward
  3745. compatibility, and is defined to be thefirst address in the list of
  3746. addresses in the hostent structure.
  3747.    The database for these calls is provided either by the configuration
  3748. file or by use of a name server.  Because of the differences in these
  3749. databases and their access protocols, the information returned may
  3750. differ.  When using the host table version of gethostbyname(), only one
  3751. address will be returned, but all listedaliases will be included.  The
  3752. name server version may return alternateaddresses, but will not provide
  3753. any aliases other than one given as argument.
  3754.  
  3755.  
  3756.  
  3757. 3.2.2   Network  Names
  3758.  
  3759. As for host names, routines for mappingnetwork names to numbers, and
  3760. back, are provided.  These routines return a netent structure:
  3761.  
  3762.  
  3763.     /*
  3764.      * Assumption here is that a network number
  3765.      * fits in 32 bits -- probably a poor one.
  3766.      */
  3767.     struct  netent -
  3768.          char    *n_name;         /* official name of net */
  3769.          char    **n_aliases;     /* alias list */
  3770.          int     n_addrtype;      /* net address type */
  3771.          int     n_net;           /* networknumber, host byte order */
  3772.     ";
  3773.  
  3774.  
  3775.    The routines getnetbyname(), andgetnetbynumber() are the network
  3776. counterparts to the host routines described above.   The routines uses
  3777. data read from AmiTCP/IP configuration file.
  3778.  
  3779.  
  3780.  
  3781. 3.2.3   Protocol Names
  3782.  
  3783. For protocols, the protoent structure defines the protocol--name mapping
  3784. used with the routines getprotobyname()and getprotobynumber():
  3785.  
  3786.  
  3787. 42    Section 3.2                  AmiTCP/IP                   System Manual
  3788.  
  3789.  
  3790.  
  3791.     struct  protoent -
  3792.          char    *p_name;         /* official protocol name */
  3793.          char    **p_aliases;     /* alias list */
  3794.          int     p_proto;         /* protocol number */
  3795.     ";
  3796.  
  3797.  
  3798.  
  3799. 3.2.4   Service  Names
  3800.  
  3801.  
  3802. Information regarding services is a bitmore complicated.  A service is
  3803. expected to reside at a specific ``port'' and employ a particular
  3804. communication protocol.  This view is consistent with the Internet
  3805. domain, but inconsistent with other network architectures.  Further, a
  3806. service may reside on multiple ports.  If this occurs,the higher level
  3807. library routines will have to be bypassed or extended.  A service mapping
  3808. is described by the servent structure:
  3809.  
  3810.  
  3811.  
  3812.     struct  servent -
  3813.          char    *s_name;         /* official service name */
  3814.          char    **s_aliases;     /* alias list */
  3815.          int     s_port;          /*port number, network byte order */
  3816.          char    *s_proto;       /* protocol to use */
  3817.     ";
  3818.  
  3819.  
  3820.    The routine getservbyname() maps service names to a servent structure
  3821. by specifying a service name and, optionally, a qualifying protocol.
  3822. Thus the call
  3823.  
  3824.  
  3825.     sp = getservbyname("telnet", NULL);
  3826.  
  3827.  
  3828. returns the service specification for atelnet server using any protocol,
  3829. while the call
  3830.  
  3831.  
  3832.     sp = getservbyname("telnet", "tcp");
  3833.  
  3834.  
  3835. returns only that telnet server which uses the TCP protocol.  The routine
  3836. getservbyport() is also provided.  The getservbyport()routine has an
  3837. interface similar to that provided by getservbyname(); an optional
  3838. protocol name may be specified to qualify lookups.
  3839.  
  3840.  
  3841.  
  3842. 3.2.5   Miscellaneous
  3843.  
  3844.  
  3845. With the support routines described above, an Internet application
  3846. program should rarely have to deal directly with addresses.  This allows
  3847. services to be developed as much as possible in a network independent
  3848. fashion.  It is clear, however, that purging all network dependencies is
  3849. very difficult.  So long as the user is required to supply network
  3850. addresses when naming services and sockets there will always some network
  3851. dependency in a program.  For example, the normal codeincluded in client
  3852. programs, such as the remote login program, is as follows:
  3853.  
  3854.  
  3855. System Manual                   AmiTCP/IP                   Section 3.2    43
  3856.  
  3857.  
  3858.  
  3859. Remote Login Client Code
  3860.  
  3861.     #include <sys/types.h>
  3862.     #include <sys/socket.h>
  3863.     #include <netinet/in.h>
  3864.     #include <stdio.h>
  3865.     #include <netdb.h>
  3866.      ...
  3867.     int main(int argc, char *argv[])
  3868.     -
  3869.             struct sockaddr_in server;
  3870.             struct servent *sp;
  3871.             struct hostent *hp;
  3872.             int s;
  3873.              ...
  3874.             sp = getservbyname("login","tcp");
  3875.             if (sp == NULL) -
  3876.                fprintf(stderr, "rlogin: tcp/login: unknown service"n");
  3877.                exit(1);
  3878.             "
  3879.             hp = gethostbyname(argv[1]);
  3880.             if (hp == NULL) -
  3881.                fprintf(stderr, "rlogin: %s: unknown host"n",argv[1]);
  3882.                exit(2);
  3883.             "
  3884.             bzero((char *)&server, sizeof (server));
  3885.             server.sin_port = sp->s_port;
  3886.             bcopy(hp->h_addr, (char *)&server.sin_addr, hp->h_length);
  3887.             server.sin_family = hp->h_addrtype;
  3888.  
  3889.  
  3890.             s = socket(AF_INET, SOCK_STREAM, 0);
  3891.             if (s < 0) -
  3892.                perror("rlogin: socket");
  3893.                exit(3);
  3894.             "
  3895.              ...
  3896.             /* Connect does the bind()for us */
  3897.  
  3898.  
  3899.             if (connect(s, (struct sockaddr *)&server, sizeof (server)) < 0) -
  3900.                perror("rlogin: connect");
  3901.                exit(5);
  3902.             "
  3903.              ...
  3904.     "
  3905.  
  3906.  
  3907.  
  3908.    (This example will be considered in more detail in section 3.3.)
  3909.  
  3910.  
  3911.  
  3912.   If we wanted to make the remote login program independent of the
  3913. Internet protocols and addressing schemewe would be forced to add a
  3914. layer of routines which masked the network dependent aspects from the
  3915. mainstream login code.  For the current facilities available in the
  3916. system this does not appear to be worthwhile.
  3917.    Aside from the address-related data base routines, there are several
  3918. other routines available in the run-timelibrary which are of interest to
  3919.  
  3920.  
  3921. 44    Section 3.3                  AmiTCP/IP                   System Manual
  3922.  
  3923.  
  3924.  
  3925. users.  These are intended mostly to simplify manipulation of names and
  3926. addresses.  The routines for manipulating variable length byte strings
  3927. and handling byte swapping of network addresses and values are summarized
  3928.  
  3929. below:8.
  3930.  
  3931.  
  3932. bcmp(s1, s2, n)
  3933.  
  3934.     Compare byte-strings; 0 if same, not 0 otherwise.
  3935.  
  3936. bcopy(s1, s2, n)
  3937.  
  3938.     Copy n bytes from s1 to s2.
  3939.  
  3940. bzero(base, n)
  3941.  
  3942.     Zero-fill n bytes starting at base.
  3943.  
  3944. htonl(val)
  3945.  
  3946.     Convert 32-bit quantity from host to network byte order.
  3947.  
  3948. htons(val)
  3949.  
  3950.     Convert 16-bit quantity from host to network byte order.
  3951.  
  3952. ntohl(val)
  3953.  
  3954.     Convert 32-bit quantity from network to host byte order.
  3955.  
  3956. ntohs(val)
  3957.  
  3958.     Convert 16-bit quantity from network to host byte order.
  3959.  
  3960.  
  3961.    The byteswapping routines are provided because the operating system
  3962. expects addresses to be supplied in network order.   Onsome
  3963. architectures, such as the VAX, host byte ordering is different than
  3964. network byte ordering.  Consequently, programs are sometimes required to
  3965. byte swap quantities.  The library routines which return network
  3966. addresses provide them in network orderso that they may simply be copied
  3967. into the structures provided to the system.   This implies users should
  3968. encounter the byte swapping problem onlywhen interpreting network
  3969. addresses.  For example, if an Internet port is to be printed out the
  3970. following code would be required:
  3971.  
  3972.     printf("port number %d"n", ntohs(sp->s_port));
  3973.  
  3974. On machines where unneeded (as on Amiga)these routines are defined as
  3975. null macros.
  3976.  
  3977.  
  3978.  
  3979. 3.3     Client/Server Model
  3980.  
  3981.  
  3982. The most commonly used paradigm in constructing distributed applications
  3983. is the client/server model.  In this scheme client applications request
  3984. services from a server process.  This implies an asymmetry in
  3985. establishing communication between the client and server which has been
  3986. ________________________________
  3987.    8The byte string functions areprovided by the C-compiler.  The byte
  3988.  
  3989. order functions are provided as preprocessor macros.
  3990.  
  3991.  
  3992. System Manual                   AmiTCP/IP                   Section 3.3    45
  3993.  
  3994.  
  3995.  
  3996. examined in section 3.1.  In this section we will lookmore closely at
  3997. the interactions between client and server, and consider some of the
  3998. problems in developing client and serverapplications.
  3999.    The client and server require a well known set of conventions before
  4000. service may be rendered (and accepted).  This set of conventions
  4001. comprises a protocol which must be implemented at both ends of a
  4002. connection.  Depending on the situation, the protocol may be symmetric or
  4003. asymmetric.  In a symmetric protocol, either side may play the master or
  4004. slave roles.  In an asymmetric protocol, one side is immutably recognized
  4005. as the master, with the other as the slave.   An example of a symmetric
  4006. protocol is the TELNET protocol used inthe Internet for remote terminal
  4007. emulation.  An example of an asymmetric protocol is theInternet file
  4008. transfer protocol, FTP. No matter whether the specific protocol used in
  4009. obtaining a service is symmetric or asymmetric, when accessing a service there
  4010. is a ``client process'' and a ``server process''.   Wewill first consider the
  4011. properties of server processes, then client processes.
  4012.    A serverprocess normally listens at a well known address for service
  4013. requests.  That is, the server process remains dormantuntil a connection
  4014. is requested by a client's connection tothe server's address.  At such a
  4015. time the server process ``wakes up'' andservices the client, performing
  4016. whatever appropriate actions the clientrequests of it.
  4017.    Alternative schemes which use a service server may be used to eliminate
  4018. a flock of server processes clogging thesystem while remaining dormant
  4019. most of the time.  For Internet servers in 4.3BSD, thisscheme has been
  4020. implemented via inetd, the so called ``internet super-server.''  Inetd
  4021. listens at a variety of ports, determined at start-up by reading a
  4022. configuration file.  When a connection is requested toa port on which
  4023. inetd is listening, inetd executes the appropriate server program to
  4024. handle the client.  Inetd will be described in more detail in section
  4025. 3.4.
  4026.  
  4027.  
  4028.  
  4029. 3.3.1   Servers
  4030.  
  4031. In 4.3BSD most servers are accessed at well known Internet addresses or
  4032. UNIX domain names.  For example, the remote login server's main loop is
  4033. of the form shown below (AmiTCP/IP way):
  4034.  
  4035.  
  4036.     main(int argc, char *argv)
  4037.     -
  4038.          int f;
  4039.          struct sockaddr_in from;
  4040.          struct servent *sp;
  4041.  
  4042.  
  4043.          sp = getservbyname("login", "tcp");
  4044.          if (sp ==NULL) -
  4045.              fprintf(stderr, "rlogind: tcp/login: unknown service"n");
  4046.              exit(1);
  4047.          "
  4048.           ...
  4049.  
  4050.  
  4051.          sin.sin_port = sp->s_port;  /* Restricted port */
  4052.           ...
  4053.  
  4054.  
  4055. 46    Section 3.3                  AmiTCP/IP                   System Manual
  4056.  
  4057.  
  4058.  
  4059.          f = socket(AF_INET, SOCK_STREAM, 0);
  4060.           ...
  4061.          if (bind(f, (struct sockaddr *) &sin, sizeof (sin)) < 0) -
  4062.           ...
  4063.          "
  4064.           ...
  4065.          listen(f, 5);
  4066.          for (;;)-
  4067.              int g, len = sizeof (from);
  4068.  
  4069.  
  4070.              g = accept(f, (struct sockaddr *)&from, &len);
  4071.              if (g < 0) -
  4072.                  if (errno != EINTR)
  4073.                       syslog(LOG_ERR, "rlogind: accept: %s", errors[errno]);
  4074.                  continue;
  4075.              "
  4076.              /*
  4077.               * AmiTCP code follows...
  4078.               */
  4079.              id = ReleaseSocket(g, UNIQUE_ID);
  4080.              startit(id, &from);
  4081.          "
  4082.     "
  4083.  
  4084.    The firststep taken by the server is look up its service definition:
  4085.  
  4086.     sp = getservbyname("login", "tcp");
  4087.     if (sp == NULL) -
  4088.          fprintf(stderr, "rlogind: tcp/login: unknown service"n");
  4089.          exit(1);
  4090.     "
  4091.  
  4092. The result of the getservbyname call isused in later portions of the
  4093. code to define the Internet port at which it listens for service requests
  4094. (indicated by a connection).
  4095.    Once a server has established a pristine environment, it creates a
  4096. socket and begins accepting service requests.   The bind() call is
  4097. required to insure the server listens atits expected location.
  4098.    The mainbody of the loop is fairly simple:
  4099.  
  4100.     for (;;) -
  4101.          int g, len = sizeof (from);
  4102.  
  4103.  
  4104.          g = accept(f, (struct sockaddr *)&from, &len);
  4105.          if (g < 0) -
  4106.              if (errno != EINTR)
  4107.                  syslog(LOG_ERR, "rlogind: accept: %s", errors[errno]);
  4108.              continue;
  4109.          "
  4110.          /*
  4111.           * AmiTCP code follows...
  4112.           */
  4113.          id = ReleaseSocket(g, UNIQUE_ID);
  4114.          startit(id,  &from);
  4115.     "
  4116.  
  4117.  
  4118. System Manual                   AmiTCP/IP                   Section 3.3    47
  4119.  
  4120.  
  4121.  
  4122.    An accept() call blocks the server until a client requests service.
  4123. This call could return a failure statusif the call is interrupted by a
  4124. signal such as CTRL-C (to be discussed in section 3.4).  Therefore, the
  4125. return value from accept() is checked toinsure a connection has actually
  4126. been established.
  4127.    With a connection in hand, servers using AmiTCP/IP socket library,
  4128. this new socket is released to an external list inside AmiTCP/IP process
  4129. via ReleaseSocket() call.  ReleaseSocket() returns an id (unique if
  4130. requested).  startit() starts a new AmigaOS task and informs the id for
  4131. it.  This new task then uses ObtainSocket() with id asargument to
  4132. receive the socket.  The address of the client is alsohandled the new
  4133. task because it requires it in authenticating clients.
  4134.  
  4135.  
  4136.  
  4137. 3.3.2   Clients
  4138.  
  4139. The client side of the remote login service was shown earlier in section
  4140. 3.2.  One can see the separate, asymmetric roles of theclient and server
  4141. clearly in the code.  The server is a passive entity, listening for
  4142. client connections, while the client process is an active entity,
  4143. initiating a connection when invoked.
  4144.    Let us consider more closely the steps taken by the client remote login
  4145. process.  As in the server process, the first step is to locate the
  4146. service definition for a remote login:
  4147.  
  4148.  
  4149.     sp = getservbyname("login", "tcp");
  4150.     if (sp == NULL) -
  4151.          fprintf(stderr, "rlogin: tcp/login: unknown service"n");
  4152.          exit(1);
  4153.     "
  4154.  
  4155.    Next thedestination host is looked up with a gethostbyname() call:
  4156.  
  4157.  
  4158.     hp = gethostbyname(argv[1]);
  4159.     if (hp == NULL) -
  4160.          fprintf(stderr, "rlogin: %s: unknown host"n", argv[1]);
  4161.          exit(2);
  4162.     "
  4163.  
  4164. With this accomplished, all that is required is to establish a connection
  4165. to the server at the requested host andstart up the remote login
  4166. protocol.  The address buffer is filled in with the Internet address and
  4167. rlogin port number of the foreign host.
  4168.  
  4169.  
  4170.     bzero((char *)&server, sizeof (server));
  4171.     server.sin_port = sp->s_port;
  4172.     bcopy(hp->h_addr, (char *) &server.sin_addr, hp->h_length);
  4173.     server.sin_family = hp->h_addrtype;
  4174.  
  4175. A socket is created, and a connection initiated.   Notethat connect()
  4176. implicitly performs a bind() call, because s is unbound.
  4177.  
  4178.  
  4179.     s = socket(hp->h_addrtype, SOCK_STREAM, 0);
  4180.     if (s < 0) -
  4181.  
  4182.  
  4183. 48    Section 3.3                  AmiTCP/IP                   System Manual
  4184.  
  4185.  
  4186.  
  4187.          perror("rlogin: socket");
  4188.          exit(3);
  4189.     "
  4190.      ...
  4191.     if (connect(s, (struct sockaddr *) &server,
  4192.              sizeof (server)) < 0) -
  4193.          perror("rlogin: connect");
  4194.          exit(4);
  4195.     "
  4196.  
  4197. The details of the remote login protocolwill not be considered here.
  4198.  
  4199.  
  4200.  
  4201. 3.3.3   Connectionless Servers
  4202.  
  4203. While connection-based services are thenorm, some services are based on
  4204. the use of datagram sockets.  One, in particular, is the ``rwho'' service
  4205. which provides users with status information for hosts connected to a
  4206. local area network.  This service, while predicated onthe ability to
  4207. broadcast information to all hosts connected to a particular network, is
  4208. of interest as an example usage of datagram sockets.
  4209.    A user onany machine running the rwho server may find out the current
  4210. status of a machine with the ruptime program.   The output generated is
  4211. illustrated below.
  4212.  
  4213.  
  4214.  
  4215. Ruptime Output
  4216.  
  4217. arpa         up   9:45,        5 users, load    1.15,    1.39,    1.31
  4218. cad          up    2+12:04,     8 users, load    4.67,    5.13,    4.59
  4219. calder       up    10:10,       0 users,load    0.27,    0.15,    0.14
  4220. dali         up   2+06:28,     9 users, load   1.04,    1.20,    1.65
  4221. degas       up    25+09:48,    0 users, load    1.49,    1.43,    1.41
  4222. ear          up    5+00:05,     0 users, load    1.51,    1.54,    1.56
  4223. ernie     down   0:24
  4224. esvax     down   17:04
  4225. ingres    down   0:26
  4226. kim          up    3+09:16,     8 users, load    2.03,    2.46,    3.11
  4227. matisse     up    3+06:18,    0 users, load    0.03,    0.03,    0.05
  4228. medea       up    3+09:39,     2 users,load    0.35,    0.37,    0.50
  4229. merlin    down   19+15:37
  4230. miro         up   1+07:20,     7 users, load   4.59,    3.28,    2.12
  4231. monet       up    1+00:43,     2 users,load    0.22,    0.09,    0.07
  4232. oz         down   16:09
  4233. statvax     up    2+15:57,    3 users, load    1.52,    1.81,    1.86
  4234. ucbvax      up    9:34,        2 users, load    6.08,   5.16,    3.28
  4235.  
  4236.  
  4237.    Status information for each host is periodically broadcast by rwho
  4238. server processes on each machine.  The same server process also receives
  4239. the status information and uses it to update a database.  This database
  4240. is then interpreted to generate the status information for each host.
  4241. Servers operate autonomously, coupled only by the local network and its
  4242. broadcast capabilities.
  4243.    Note thatthe use of broadcast for such a task is fairly inefficient,
  4244. as all hosts must process each message,whether or not using an rwho
  4245.  
  4246.  
  4247. System Manual                   AmiTCP/IP                   Section 3.3    49
  4248.  
  4249.  
  4250.  
  4251. server.  Unless such a service is sufficiently universal and is
  4252. frequently used, the expense of periodicbroadcasts outweighs the
  4253. simplicity.
  4254.  
  4255.    The rwhoserver, in a simplified form, is pictured next9:
  4256.  
  4257.  
  4258.     BYTE alrmsig;
  4259.  
  4260.  
  4261.     main()
  4262.     -
  4263.          long on;
  4264.          fd_set readfds;
  4265.           ...
  4266.          sp = getservbyname("who", "udp");
  4267.          sin.sin_port = sp->s_port;
  4268.          net = getnetbyname("localnet");
  4269.          sin.sin_addr = inet_makeaddr(INADDR_ANY, net);
  4270.           ...
  4271.          s = socket(AF_INET, SOCK_DGRAM, 0);
  4272.           ...
  4273.          on = 1;
  4274.          if (setsockopt(s, SOL_SOCKET, SO_BROADCAST, &on, sizeof(on)) < 0) -
  4275.              syslog(LOG_ERR, "rwhod: setsockopt SO_BROADCAST: %s",
  4276.                     strerror(errno));
  4277.              exit(1);
  4278.          "
  4279.          bind(s, (struct sockaddr *) &sin, sizeof (sin));
  4280.           ...
  4281.          alrmsig =AllocSignal(-1);
  4282.          onalrm();/* activate and handle periodic alarm system */
  4283.  
  4284.  
  4285.          FD_ZERO(&readfds);
  4286.          FD_SET(s, &readfds);
  4287.  
  4288.  
  4289.          for (;;)-
  4290.              struct whod wd;
  4291.              struct sockaddr_in from;
  4292.              int n, cc, whod, len = sizeof (from);
  4293.              ULONG alrmmask;
  4294.  
  4295.  
  4296.              alrmmask = 1 << alrmsig;
  4297.              n = WaitSelect(s, &readfds, NULL,NULL, NULL, &alrmmask);
  4298.              if (n < 0) -
  4299.                  syslog(LOG_ERR, "rwhod: WaitSelect: %s", strerror(errno));
  4300.                  exit(1);
  4301.              "
  4302.              if (alrmmask)
  4303.                onalrm(); /* handles the alarm */
  4304.              if (n > 0) -
  4305.                  cc = recvfrom(s, (char *)&wd, sizeof (wd), 0,
  4306.                                 (struct sockaddr *)&from, &len);
  4307.                  if (cc <= 0) -
  4308. ________________________________
  4309.    9A real code must always test the return values of various services
  4310.  
  4311. against errors.  Thes e tests are partly omitted from this code to show
  4312. the matters important to this section.
  4313.  
  4314.  
  4315. 50    Section 3.3                  AmiTCP/IP                   System Manual
  4316.  
  4317.  
  4318.  
  4319.                       if (cc < 0)
  4320.                           syslog(LOG_ERR, "rwhod: recv: %s", strerror(errno));
  4321.                       continue;
  4322.                  "
  4323.                  if (from.sin_port != sin.sin_port) -
  4324.                       syslog(LOG_ERR, "rwhod: %ld: bad from port",
  4325.                              ntohs(from.sin_port));
  4326.                       continue;
  4327.                  "
  4328.                  ...
  4329.                  if (!verify(wd.wd_hostname)) -
  4330.                       syslog(LOG_ERR, "rwhod: malformed host name from %lx",
  4331.                              ntohl(from.sin_addr.s_addr));
  4332.                       continue;
  4333.                  "
  4334.                  (void) sprintf(path, "%s/whod.%s", RWHODIR, wd.wd_hostname);
  4335.                  whod = open(path, O_WRONLY _ O_CREAT _ O_TRUNC, 0666);
  4336.                  ...
  4337.                  (void) time(&wd.wd_recvtime);
  4338.                  (void) write(whod, (char *)&wd, cc);
  4339.                  (void) close(whod);
  4340.              "
  4341.          "
  4342.     "
  4343.  
  4344.  
  4345.    There aretwo separate tasks performed by the server.  The first task
  4346. is to act as a receiver of status information broadcast by other hosts on
  4347. the network.  This job is carried out in the main loopof the program.
  4348. Packets received at the rwho port are interrogated to insure they've been
  4349. sent by another rwho server process, then are time stamped with their
  4350. arrival time and used to update a file indicating the status of the host.
  4351. When a host has not been heard from foran extended period of time, the
  4352. database interpretation routines assumethe host is down and indicate
  4353. such on the status reports.  This algorithm is prone toerror as a server
  4354. may be down while a host is actually up,but serves our current needs.
  4355.    The second task performed by the server is to supply information
  4356. regarding the status of its host.  This involves periodically acquiring
  4357. system status information, packaging itup in a message and broadcasting
  4358. it on the local network for other rwho servers to hear.  The supply
  4359. function is triggered by a timer and runs off a signal.  Locating the
  4360. system status information is somewhat involved, but uninteresting.
  4361. Deciding where to transmit the resultantpacket is somewhat
  4362. problematical, however.
  4363.    Status information must be broadcast on the local network.  For
  4364. networks which do not support the notionof broadcast another scheme must
  4365. be used to simulate or replace broadcasting.   One possibility is to
  4366. enumerate the known neighbors (based onthe status messages received from
  4367. other rwho servers).  This, unfortunately, requires some bootstrapping
  4368. information, for a server will have no idea what machines are its
  4369. neighbors until it receives status messages from them.  Therefore, if all
  4370. machines on a net are freshly booted, nomachine will have any known
  4371. neighbors and thus never receive, or send, any status information.  This
  4372. is the identical problem faced by the routing table management process in
  4373.  
  4374.  
  4375. System Manual                   AmiTCP/IP                   Section 3.4    51
  4376.  
  4377.  
  4378.  
  4379. propagating routing status information.  The standard solution, unsatisfactory
  4380. as it may be, is to inform one or more servers of known neighbors and request
  4381. that theyalways communicate with these neighbors.   Ifeach server has at least
  4382. one neighbor supplied to it, status information may then propagate through
  4383. a neighbor to hosts which are not (possibly) directly neighbors.  If the server
  4384. is able to support networks which provide a broadcast capability, as well as
  4385. those which do not, then networks with an arbitrary topology may share status
  4386.  
  4387. information10
  4388.    It is important that software operating in a distributed environment
  4389. not have any site-dependent informationcompiled into it.  This would
  4390. require a separate copy of the server ateach host and make maintenance a
  4391. severe headache.  4.3BSD attempts to isolate host-specific information
  4392. from applications by providing system calls which return the necessary
  4393.  
  4394. information11.  A mechanism exists, in the form of an IoctlSocket() call,
  4395. for finding the collection of networks to which a host is directly
  4396. connected.  Further, a local network broadcasting mechanism has been
  4397. implemented at the socket level.  Combining these two features allows a
  4398. process to broadcast on any directly connected local network which
  4399. supports the notion of broadcasting in asite independent manner.  This allows
  4400. 4.3BSD to solve the problem of decidinghow to propagate status information
  4401. in the case of rwho, or more generally in broadcasting:  Such status information
  4402. is broadcast to connected networks at the socket level, where the connected
  4403. networks have been obtained via the appropriate ioctl calls.  The specifics
  4404. of such broadcastings are complex, however, and will be covered in section
  4405. 3.4.
  4406.  
  4407.  
  4408.  
  4409. 3.4     Advanced Topics
  4410.  
  4411.  
  4412. A number of facilities have yet to be discussed.   Formost users of the
  4413. AmiTCP/IP the mechanisms already described will suffice in constructing
  4414. distributed applications.  However, others will find the need to utilize
  4415. some of the features which we consider in this section.
  4416.  
  4417.  
  4418.  
  4419. 3.4.1   OutOf Band Data
  4420.  
  4421. The stream socket abstraction includes the notion of ``out of band''
  4422. data.  Out of band data is a logically independent transmission channel
  4423. associated with each pair of connected stream sockets.  Out of band data
  4424. is delivered to the user independently of normal data.  The abstraction
  4425. defines that the out of band data facilities must support the reliable
  4426. delivery of at least one out of band message at a time.  This message may
  4427. contain at least one byte of data, and at least one message may be
  4428. pending delivery to the user at any onetime.   For communications
  4429. protocols which support only in-band signaling (i.e.  the urgent data is
  4430. ________________________________
  4431.   10One must, however, be concerned about loops.  That is, if a host is
  4432.  
  4433. connected to multiple networks, it willreceive status information from
  4434. itself.  This can lead to an endless, wasteful, exchange of information.
  4435.   11An example of such a system call is the gethostname() call which returns
  4436.  
  4437. the host's official name.
  4438.  
  4439.  
  4440. 52    Section 3.4                  AmiTCP/IP                   System Manual
  4441.  
  4442.  
  4443.  
  4444. delivered in sequence with the normal data), the system normally extracts
  4445. the data from the normal data stream andstores it separately.  This allows
  4446. users to choose between receiving the urgent data in order and receiving it
  4447. out of sequence without having to bufferall the intervening data.  It is possib*
  4448.  *le
  4449. to ``peek'' (via MSG_PEEK) at out of band data.  If the socket has an owner,
  4450. a signal is generated when the protocolis notified of its existence.  A process
  4451. can set the task to be informed by a signal via the appropriate IoctlSocket()
  4452. and SetSocketSignals() calls, as described below in section 3.4.3.  If multiple
  4453. sockets may have out of band data awaiting delivery, a select() call for except*
  4454.  *ional
  4455. conditions may be used to determine those sockets with such data pending.  Neit*
  4456.  *her
  4457. the signal nor the select() indicate theactual arrival of the out-of-band
  4458. data, but only notification that it is pending.
  4459.    In addition to the information passed, a logical mark is placed in the
  4460. data stream to indicate the point at which the out of band data was
  4461.  
  4462. sent12.  The remote login and remote shell applications use this facility
  4463. to propagate signals between client andserver processes.  When a signal
  4464. flushs any pending output from the remote process(es), all data up to the
  4465. mark in the data stream is discarded.
  4466.    To send an out of band message the MSG_OOB flag is supplied to a send()
  4467. or sendto() calls, while to receive outof band data MSG_OOB should be
  4468. indicated when performing a recvfrom() or recv() call.  To find out if
  4469. the read pointer is currently pointing at the mark in the data stream,
  4470. the SIOCATMARK ioctl is provided:
  4471.  
  4472.  
  4473.     IoctlSocket(s, SIOCATMARK, &yes);
  4474.  
  4475. If yes is a 1 on return, the next read will return data after the mark.
  4476. Otherwise (assuming out of band data hasarrived), the next read will
  4477. provide data sent by the client prior totransmission of the out of band
  4478. signal.  The routine used in the remote login process to flush output on
  4479. receipt of an interrupt or quit signal is shown below:
  4480.  
  4481.     #include <sys/ioctl.h>
  4482.     #include <sys/socket.h>
  4483.      ...
  4484.     oob()
  4485.     -
  4486.          int mark;
  4487.          char waste[BUFSIZ];
  4488.  
  4489.  
  4490.          /* flushterminal I/O on receipt of out of band data */
  4491.  
  4492.  
  4493.          for (;;)-
  4494.              if (IoctlSocket(rem, SIOCATMARK,&mark) < 0) -
  4495.                  perror("IoctlSocket");
  4496.                  break;
  4497.              "
  4498.              if (mark)
  4499.                  break;
  4500.              recv(rem, waste, sizeof (waste),0);
  4501. ________________________________
  4502.   12AmiTCP/IP follows the BSD interpretation of the RFC 793 in which the
  4503.  
  4504. concept of out-of-band data is introduced.   The BSD interpretation is in
  4505. conflict with (later) defined Host Requirements laid down in RFC 1122.
  4506.  
  4507.  
  4508. System Manual                   AmiTCP/IP                   Section 3.4    53
  4509.  
  4510.  
  4511.  
  4512.          "
  4513.          if (recv(rem, &mark, 1, MSG_OOB) < 0) -
  4514.              perror("recv");
  4515.               ...
  4516.          "
  4517.           ...
  4518.     "
  4519.  
  4520.    The normal data up to the mark if first read (discarding it), then the
  4521. out-of-band byte is read.
  4522.    A processmay also read or peek at the out-of-band data without first
  4523. reading up to the mark.  This is more difficult when the underlying
  4524. protocol delivers the urgent data in-band with the normal data, and only
  4525. sends notification of its presence aheadof time (e.g., the TCP protocol
  4526. used to implement streams in the Internet domain).   With such protocols,
  4527. the out-of-band byte may not yet have arrived when a recv() is done with
  4528. the MSG_OOB flag.  In that case, the call will return an error of
  4529. EWOULDBLOCK. Worse, there may be enoughin-band data in the input buffer
  4530. that normal flow control prevents the peer from sending the urgent data
  4531. until the buffer is cleared.  The process must then read enough of the
  4532. queued data that the urgent data may bedelivered.
  4533.    Certain programs that use multiple bytes of urgent data and must handle
  4534. multiple urgent signals (e.g., telnet) need to retain the position of
  4535. urgent data within the stream.  This treatment is available as a
  4536. socket-level option, SO_OOBINLINE; see function reference for
  4537. setsockopt() for usage.  With this option, the positionof urgent data
  4538. (the ``mark'') is retained, but the urgent data immediately follows the
  4539. mark within the normal data stream returned without the MSG_OOB flag.
  4540. Reception of multiple urgent indicationscauses the mark to move, but no
  4541. out-of-band data are lost.
  4542.  
  4543.  
  4544.  
  4545. 3.4.2   Non-Blocking Sockets
  4546.  
  4547. It is occasionally convenient to make use of sockets which do not block;
  4548. that is, I/O requests which cannot complete immediately and would
  4549. therefore cause the process to be suspended awaiting completion are not
  4550. executed, and an error code is returned.  Once a sockethas been created
  4551. via the socket() call, it may be markedas non-blocking by IoctlSocket()
  4552. as follows:
  4553.  
  4554.     #include <sys/ioctl.h>
  4555.      ...
  4556.     int      s;
  4557.      long     yes = TRUE;
  4558.      ...
  4559.     s = socket(AF_INET, SOCK_STREAM, 0);
  4560.      ...
  4561.     if (IoctlSocket(s, FIONBIO, &yes) < 0)
  4562.          perror("IoctlSocket FIONBIO");
  4563.          exit(1);
  4564.     "
  4565.      ...
  4566.  
  4567.    When performing non-blocking I/O on sockets, one must be careful to
  4568. check for the error EWOULDBLOCK (storedin the global variable errno),
  4569.  
  4570.  
  4571. 54    Section 3.4                  AmiTCP/IP                   System Manual
  4572.  
  4573.  
  4574.  
  4575. which occurs when an operation would normally block, but the socket it
  4576. was performed on is marked as non-blocking.   In particular, accept(),
  4577. connect(), send(), sendto(), recv() andrecvto() can all return
  4578. EWOULDBLOCK, and processes should be prepared to deal with such return
  4579. codes.  If an operation such as a send() cannot be donein its entirety,
  4580. but partial writes are sensible (for example, when using a stream
  4581. socket), the data that can be sent immediately will be processed, and the
  4582. return value will indicate the amount actually sent.
  4583.  
  4584.  
  4585.  
  4586. 3.4.3   Signal Driven Socket I/O
  4587.  
  4588. The AmiTCP/IP allows a task to be notified via a signal when a socket
  4589. has either normal or out-of-band data waiting to be read.  Use of this
  4590. facility requres four steps:
  4591.  
  4592.  1. The signals to be used must be allocated with Exec AllocSignal()
  4593.     call.
  4594.  
  4595.  2. The allocated signal(s) must be registered to the AmiTCP/IP with the
  4596.     SetSocketSignals() call.  The signals registered with
  4597.     SetSocketSignals() affect all sockets of the calling task, so this is
  4598.     usually done only after OpenLibrary() call.
  4599.  
  4600.  3. The owner of the socket must be set to the task itself (note that the
  4601.     owner of a socket is unspecified by default).  This is accomplished
  4602.     by the use of an IoctlSocket() call.
  4603.  
  4604.  4. Asynchronous notification for the socket must be enabled with another
  4605.     IoctlSocket() call
  4606.  
  4607. Note that it is application's responsibility to react on received
  4608. signals.
  4609.    Sample code to allow a given process to receive information on pending
  4610. I/O requests as they occur for a sockets is given below:
  4611.  
  4612.     #include <exec/tasks.h>
  4613.     #include <sys/ioctl.h>
  4614.      ...
  4615.     BYTE SIGIO = -1, SIGURG = -1;
  4616.      ...
  4617.     struct Task *thisTask = FindTask(NULL); /* our task pointer */
  4618.     long yes = TRUE;
  4619.  
  4620.  
  4621.     /* Allocate signals for asynchronous notification */
  4622.  
  4623.  
  4624.     if ((SIGIO = AllocSignal(-1)) == -1) -
  4625.          fprintf(stderr, "allocSignal failed."n");
  4626.          exit(1);
  4627.     "
  4628.     atexit(freeSignals); /* free allocated signals on exit */
  4629.     if ((SIGURG = AllocSignal(-1)) == -1) -
  4630.          fprintf(stderr, "allocSignal failed."n");
  4631.          exit(1);
  4632.     "
  4633.  
  4634.  
  4635. System Manual                   AmiTCP/IP                   Section 3.4    55
  4636.  
  4637.  
  4638.  
  4639.     /* Set socket signals for this task */
  4640.  
  4641.  
  4642.     SetSocketSignals(SIGBREAKF_CTRL_C, 1 << SIGIO, 1 << SIGURG);
  4643.  
  4644.  
  4645.     /* Set the process receiving SIGIO/SIGURG signals to us */
  4646.  
  4647.  
  4648.     if (IoctlSocket(s, FIOSETOWN, &thisTask) < 0) -
  4649.          perror("IoctlSocket FIOSETOWN");
  4650.          exit(1);
  4651.     "
  4652.  
  4653.  
  4654.     /* Allow receipt of asynchronous I/O signals */
  4655.  
  4656.  
  4657.     if (IoctlSocket(s, FIOASYNC, &yes) < 0) -
  4658.          perror("IoctlSocket FIOASYNC");
  4659.          exit(1);
  4660.     "
  4661.  
  4662.  
  4663.  
  4664. 3.4.4   Selecting Specific Protocols
  4665.  
  4666. If the third argument to the socket() call is 0, socket will select a
  4667. default protocol to use with the returned socket of the type requested.
  4668. The default protocol is usually correct,and alternate choices are not
  4669. usually available.  However, when using ``raw'' socketsto communicate
  4670. directly with lower-level protocols or hardware interfaces, the protocol
  4671. argument may be important for setting updemultiplexing.  For example,
  4672. raw sockets in the Internet family may be used to implement a new
  4673. protocol above IP, and the socket will receive packets only for the
  4674. protocol specified.  To obtain a particular protocol one determines the
  4675. protocol number as defined within the communication domain.  For the
  4676. Internet domain one may use one of the library routines discussed in section
  4677. 3.2, such as getprotobyname():
  4678.  
  4679.     #include <sys/types.h>
  4680.     #include <sys/socket.h>
  4681.     #include <netinet/in.h>
  4682.     #include <netdb.h>
  4683.      ...
  4684.     pp = getprotobyname("newtcp");
  4685.     s = socket(AF_INET, SOCK_STREAM, pp->p_proto);
  4686.  
  4687. This would result in a socket s using astream based connection, but with
  4688. protocol type of ``newtcp'' instead of the default ``tcp.''
  4689.  
  4690.  
  4691.  
  4692. 3.4.5   Address  Binding
  4693.  
  4694. As was mentioned in section 3.1, bindingaddresses to sockets in the
  4695. Internet domains can be fairly complex.  As a brief reminder, these
  4696. associations are composed of local and foreign addresses, and local and
  4697. foreign ports.  Port numbers are allocated out of separate spaces, one
  4698. for each system and one for each domainon that system.  Through the
  4699. bind() call, a process may specify halfof an association, the <local
  4700. address, local port> part, while the connect() and accept() calls are
  4701.  
  4702.  
  4703. 56    Section 3.4                  AmiTCP/IP                   System Manual
  4704.  
  4705.  
  4706.  
  4707. used to complete a socket's associationby specifying the <foreign
  4708. address, foreign port> part.  Since the association iscreated in two
  4709. steps the association uniqueness requirement indicated previously could
  4710. be violated unless care is taken.  Further, it is unrealistic to expect user
  4711. programs to always know proper values touse for the local address and local
  4712. port since a host may reside on multiplenetworks and the set of allocated
  4713. port numbers is not directly accessibleto a user.
  4714.    To simplify local address binding in the Internet domain the notion of
  4715. a ``wildcard'' address has been provided.   When an address is specified
  4716. as INADDR_ANY (a manifest constant defined in file netinet/in.h), the
  4717. system interprets the address as ``any valid address''.  For example, to
  4718. bind a specific port number to a socket,but leave the local address
  4719. unspecified, the following code might beused:
  4720.  
  4721.     #include <sys/types.h>
  4722.     #include <netinet/in.h>
  4723.      ...
  4724.     struct sockaddr_in sin;
  4725.      ...
  4726.     s = socket(AF_INET, SOCK_STREAM, 0);
  4727.     sin.sin_family = AF_INET;
  4728.     sin.sin_addr.s_addr = htonl(INADDR_ANY);
  4729.     sin.sin_port = htons(MYPORT);
  4730.     bzero(sin.sin_zero, sizeof(sin.sin_zero));
  4731.     bind(s, (struct sockaddr *) &sin, sizeof (sin));
  4732.  
  4733. Sockets with wildcarded local addressesmay receive messages directed to
  4734. the specified port number, and sent to any of the possible addresses
  4735. assigned to a host.  For example, if a host has addresses 128.32.0.4 and
  4736. 10.0.0.78, and a socket is bound as above, the process will be able to
  4737. accept connection requests which are addressed to 128.32.0.4 or
  4738. 10.0.0.78.  If a server process wished to only allow hosts on a given
  4739. network connect to it, it would bind theaddress of the host on the
  4740. appropriate network.
  4741.    In a similar fashion, a local port may be left unspecified (specified
  4742. as zero), in which case the system willselect an appropriate port number
  4743. for it.  For example, to bind a specific local addressto a socket, but
  4744. to leave the local port number unspecified:
  4745.  
  4746.     hp = gethostbyname(hostname);
  4747.     if (hp == NULL) -
  4748.           ...
  4749.     "
  4750.     bzero(&sin, sizeof(sin));
  4751.     bcopy(hp->h_addr, (char *) sin.sin_addr, hp->h_length);
  4752.     sin.sin_port = htons(0);
  4753.     bind(s, (struct sockaddr *) &sin, sizeof (sin));
  4754.  
  4755. The system selects the local port numberbased on two criteria.  The
  4756. first is that on 4BSD systems, Internetports below IPPORT_RESERVED
  4757.  
  4758. (1024) are reserved for privileged processes13 ; Internet ports above
  4759. ________________________________
  4760.   13All processes in AmigaOS are considered as privileged.
  4761.  
  4762.  
  4763. System Manual                   AmiTCP/IP                   Section 3.4    57
  4764.  
  4765.  
  4766.  
  4767. IPPORT_USERRESERVED (5000) are reserved for non-privileged servers.  The
  4768. second is that the port number is not currently bound to some other
  4769. socket.  In order to find a free Internet port number in the privileged
  4770. range the rresvport() library routine may be used as follows to return a
  4771. stream socket in with a privileged portnumber:
  4772.  
  4773.     int lport = IPPORT_RESERVED - 1;
  4774.     int s;
  4775.     s = rresvport(&lport);
  4776.     if (s < 0) -
  4777.          if (errno== EAGAIN)
  4778.              fprintf(stderr, "socket: all ports in use"n");
  4779.          else
  4780.              perror("rresvport: socket");
  4781.           ...
  4782.     "
  4783.  
  4784. The restriction on allocating ports wasdone to allow processes executing
  4785. in a secure environment to perform authentication based on the
  4786. originating address and port number.  For example, therlogin command
  4787. allows users to log in across a networkwithout being asked for a
  4788. password, if two conditions hold:  First, the name of the system the user
  4789.  
  4790. is logging in from is in the file AmiTCP:db/hosts.equiv14  on the system
  4791. he is logging into (or the system name and the user name are in the
  4792. user's .rhosts file in the user's home directory), and second, that the
  4793. user's rlogin process is coming from a privileged port on the machine
  4794. from which he is logging.  The port number and networkaddress of the
  4795. machine from which the user is logging in can be determined either by the from
  4796. result of the accept() call, or from thegetpeername() call.
  4797.    In certain cases the algorithm used by the system in selecting port
  4798. numbers is unsuitable for an application.   This is because associations
  4799. are created in a two step process.  For example, the Internet file
  4800. transfer protocol, FTP, specifies that data connections must always
  4801. originate from the same local port.  However, duplicateassociations are
  4802. avoided by connecting to different foreign ports.   Inthis situation the
  4803. system would disallow binding the same local address and port number to a
  4804. socket if a previous data connection's socket still existed.  To override
  4805. the default port selection algorithm, anoption call must be performed
  4806. prior to address binding:
  4807.  
  4808.      ...
  4809.      long     on = 1;
  4810.      ...
  4811.     setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
  4812.     bind(s, (struct sockaddr *) &sin, sizeof (sin));
  4813.  
  4814. With the above call, local addresses maybe bound which are already in
  4815. use.  This does not violate the uniqueness requirementas the system
  4816. still checks at connect time to be sureany other sockets with the same
  4817. local address and port do not have the same foreign address and port.  If
  4818. the association already exists, the error EADDRINUSE is returned.
  4819. ________________________________
  4820.   14In UNIX /etc/hosts.equiv
  4821.  
  4822.  
  4823. 58    Section 3.4                  AmiTCP/IP                   System Manual
  4824.  
  4825.  
  4826.  
  4827. 3.4.6   Broadcasting And Determining Network Configuration
  4828.  
  4829. By using a datagram socket, it is possible to send broadcast packets on
  4830. many networks supported by the system.  The network itself must support
  4831. broadcast; the system provides no simulation of broadcast in software.
  4832. Broadcast messages can place a high loadon a network since they force
  4833. every host on the network to service them.   Consequently, the ability to
  4834. send broadcast packets has been limitedto sockets which are explicitly
  4835. marked as allowing broadcasting.  Broadcast is typically used for one of
  4836. two reasons:  it is desired to find a resource on a local network without
  4837. prior knowledge of its address, or important functions such as routing
  4838. require that information be sent to allaccessible neighbors.
  4839.    To send abroadcast message, a datagram socket should be created:
  4840.  
  4841.     s = socket(AF_INET, SOCK_DGRAM, 0);
  4842.  
  4843. The socket is marked as allowing broadcasting,
  4844.  
  4845.      long     on = 1;
  4846.  
  4847.  
  4848.     setsockopt(s, SOL_SOCKET, SO_BROADCAST, &on, sizeof (on));
  4849.  
  4850. and at least a port number should be bound to the socket:
  4851.  
  4852.     sin.sin_family = AF_INET;
  4853.     sin.sin_addr.s_addr = htonl(INADDR_ANY);
  4854.     sin.sin_port = htons(MYPORT);
  4855.     bzero(sin.sin_zero, sizeof(sin.sin_zero));
  4856.     bind(s, (struct sockaddr *) &sin, sizeof (sin));
  4857.  
  4858. The destination address of the message to be broadcast depends on the
  4859. network(s) on which the message is to bebroadcast.   The Internet domain
  4860. supports a shorthand notation for broadcast on the local network, the
  4861. address INADDR_BROADCAST (defined in netinet/in.h).  To determine the
  4862. list of addresses for all reachable neighbors requires knowledge of the
  4863. networks to which the host is connected.  Since this information should
  4864. be obtained in a host independent fashion and may be impossible to
  4865. derive, 4.3BSD provides a method of retrieving this information from the
  4866. system data structures.  The SIOCGIFCONF IoctlSocket()call returns the
  4867. interface configuration of a host in theform of a single ifconf
  4868. structure; this structure contains a ``data area'' which is made up of an array
  4869. of of ifreq structures, one for each network interface to which the host is
  4870. connected.  These structures are defined in net/if.h asfollows:
  4871.  
  4872.     struct ifconf -
  4873.          int ifc_len;      /* size of associated buffer */
  4874.          union -
  4875.              caddr_t         ifcu_buf;
  4876.              struct ifreq *ifcu_req;
  4877.          " ifc_ifcu;
  4878.     ";
  4879.  
  4880.  
  4881.     #define ifc_buf     ifc_ifcu.ifcu_buf/* buffer address */
  4882.     #define ifc_req     ifc_ifcu.ifcu_req/* array of structures returned */
  4883.  
  4884.  
  4885.      #define IFNAMSIZ     64
  4886.  
  4887.  
  4888. System Manual                   AmiTCP/IP                   Section 3.4    59
  4889.  
  4890.  
  4891.  
  4892.     struct ifreq -
  4893.          char   ifr_name[IFNAMSIZ]; /*if name, e.g. "en0" */
  4894.          union -
  4895.              struct sockaddr ifru_addr;
  4896.              struct sockaddr ifru_dstaddr;
  4897.              struct sockaddr ifru_broadaddr;
  4898.              short  ifru_flags;
  4899.              caddr_t         ifru_data;
  4900.          " ifr_ifru;
  4901.     ";
  4902.  
  4903.  
  4904.      #define ifr_addr      ifr_ifru.ifru_addr     /* address */
  4905.     #define ifr_dstaddr   ifr_ifru.ifru_dstaddr /* other end of p-to-p link */
  4906.     #define ifr_broadaddr ifr_ifru.ifru_broadaddr /* broadcast address */
  4907.     #define ifr_flags     ifr_ifru.ifru_flags   /* flags */
  4908.      #define ifr_data      ifr_ifru.ifru_data     /* for use by interface */
  4909.  
  4910.    The actual call which obtains the interface configuration is
  4911.  
  4912.     struct ifconf ifc;
  4913.     char buf[BUFSIZ];
  4914.  
  4915.  
  4916.     ifc.ifc_len = sizeof (buf);
  4917.     ifc.ifc_buf = buf;
  4918.     if (IoctlSocket(s, SIOCGIFCONF, (char *) &ifc) < 0) -
  4919.           ...
  4920.     "
  4921.  
  4922. After this call buf will contain one ifreq structure for each network to
  4923. which the host is connected, and ifc.ifc_len will have been modified to
  4924. reflect the number of bytes used by theifreq structures.
  4925.    For eachstructure there exists a set of ``interface flags'' which tell
  4926. whether the network corresponding to that interface is up or down, point
  4927. to point or broadcast, etc.  The SIOCGIFFLAGS IoctlSocket() retrieves
  4928. these flags for an interface specified by an ifreq structure as follows:
  4929.  
  4930.     struct ifreq *ifr;
  4931.  
  4932.  
  4933.     ifr = ifc.ifc_req;
  4934.  
  4935.  
  4936.     for (n = ifc.ifc_len / sizeof (struct ifreq); --n >= 0; ifr++) -
  4937.          /*
  4938.           * We must be careful that we don't use an interface
  4939.           * devoted to anaddress family other than those intended;
  4940.           * if we were interested in NS interfaces, the
  4941.           * AF_INET wouldbe AF_NS.
  4942.           */
  4943.          if (ifr->ifr_addr.sa_family != AF_INET)
  4944.              continue;
  4945.          if (IoctlSocket(s, SIOCGIFFLAGS, (char *) ifr) < 0) -
  4946.               ...
  4947.          "
  4948.          /*
  4949.  
  4950.  
  4951. 60    Section 3.4                  AmiTCP/IP                   System Manual
  4952.  
  4953.  
  4954.  
  4955.           * Skip boring cases.
  4956.           */
  4957.          if ((ifr->ifr_flags & IFF_UP) == 0 __
  4958.              (ifr->ifr_flags & IFF_LOOPBACK) __
  4959.              (ifr->ifr_flags & (IFF_BROADCAST_ IFF_POINTTOPOINT)) == 0)
  4960.              continue;
  4961.  
  4962. Once the flags have been obtained, the broadcast address must be
  4963. obtained.  In the case of broadcast networks this is done via the
  4964. SIOCGIFBRDADDR IoctlSocket(), while forpoint-to-point networks the
  4965. address of the destination host is obtained with SIOCGIFDSTADDR.
  4966.  
  4967.     struct sockaddr dst;
  4968.  
  4969.  
  4970.     if (ifr->ifr_flags & IFF_POINTTOPOINT) -
  4971.          if (IoctlSocket(s, SIOCGIFDSTADDR, (char *) ifr) < 0) -
  4972.               ...
  4973.          "
  4974.          bcopy((char *) ifr->ifr_dstaddr, (char *) &dst,
  4975.                sizeof (ifr->ifr_dstaddr));
  4976.     " else if (ifr->ifr_flags & IFF_BROADCAST) -
  4977.          if (IoctlSocket(s, SIOCGIFBRDADDR, (char *) ifr) < 0) -
  4978.               ...
  4979.          "
  4980.          bcopy((char *) ifr->ifr_broadaddr, (char *) &dst,
  4981.                sizeof (ifr->ifr_broadaddr));
  4982.     "
  4983.  
  4984. After the appropriate ioctl's have obtained the broadcast or destination
  4985. address (now in dst), the sendto() callmay be used:
  4986.  
  4987.          sendto(s,buf, buflen, 0, (struct sockaddr *)&dst, sizeof (dst));
  4988.     "
  4989.  
  4990. In the above loop one sendto() occurs for every interface to which the
  4991. host is connected that supports the notion of broadcast or point-to-point
  4992. addressing.  If a process only wished to send broadcastmessages on a
  4993. given network, code similar to that outlined above would be used, but the
  4994. loop would need to find the correct destination address.
  4995.    Receivedbroadcast messages contain the senders address and port, as
  4996. datagram sockets are bound before a message is allowed to go out.
  4997.  
  4998.  
  4999.  
  5000. AmiTCP/IP specific extensions
  5001.  
  5002. Extensions to interface ioctls
  5003.  
  5004. The following ioctls are used to configure protocol and hardware specific
  5005. properties of a sana_softc interface.  They are used in the AmiTCP/IP
  5006. only.
  5007.  
  5008. SIOCSSANATAGS  Set SANA-II specific properties with a tag list.
  5009.  
  5010. SIOCGSANATAGS  Get SANA-II specific properties into the
  5011.     wiretype_parameters structure and a user tag list.
  5012.  
  5013.     These ioctls use the following structure as a argument:
  5014.  
  5015.  
  5016. System Manual                   AmiTCP/IP                   Section 3.4    61
  5017.  
  5018.  
  5019.  
  5020.          struct wiretype_parameters
  5021.          -
  5022.            ULONG  wiretype;       /* the wiretype of the interface */
  5023.            WORD   flags;                                /* iff_flags */
  5024.            struct TagItem *tags;         /* tag list user provides */
  5025.          ";
  5026.  
  5027.  
  5028. SIOCGARPT  Getthe contents of an ARP mapping cache into a struct arpreq
  5029.     table.
  5030.  
  5031.     This ioctl takes the following arptabreq structure as an argument:
  5032.  
  5033.  
  5034.          /*
  5035.           * An AmiTCP/IP specific ARP table ioctl request
  5036.           */
  5037.          struct arptabreq -
  5038.             struct arpreq atr_arpreq;  /* To identify theinterface */
  5039.             long   atr_size;           /* # of elementsin atr_table */
  5040.             long   atr_inuse;                /* # of elements in use */
  5041.             struct arpreq *atr_table;
  5042.          ";
  5043.  
  5044.  
  5045.     The atr_arpreq specifies the used interface.  The hardware address
  5046.     for the interface is returned in the arp_ha field of atr_arpreq
  5047.     structure.
  5048.  
  5049.     The SIOCGARPT ioctl reads at most atr_size entries from the cache
  5050.     into the user supplied buffer atr_table, if it is not NULL. Actual
  5051.     amount of returned entries is returned in atr_size.  The current
  5052.     amount of cached mappings is returned in the atr_inuse.
  5053.  
  5054.  
  5055.  
  5056. 3.4.7   Socket  Options
  5057.  
  5058. It is possible to set and get a number of options on sockets via the
  5059. setsockopt() and getsockopt() calls.  These options include such things
  5060. as marking a socket for broadcasting, not to route, to linger on close,
  5061. etc.  The general forms of the calls are:
  5062.  
  5063.     setsockopt(s, level, optname, optval, optlen);
  5064.  
  5065. and
  5066.  
  5067.     getsockopt(s, level, optname, optval, optlen);
  5068.  
  5069.    The parameters to the calls are as follows:  s is the socket on which
  5070. the option is to be applied.  level specifies the protocol layer on which
  5071. the option is to be applied; in most cases this is the ``socket level'',
  5072. indicated by the symbolic constant SOL_SOCKET, defined in sys/socket.h.
  5073. The actual option is specified in optname, and is a symbolic constant
  5074. also defined in sys/socket.h.  optval and optlen pointto the value of
  5075. the option (in most cases, whether the option is to be turned on or off),
  5076. and the length of the value of the option, respectively.  For
  5077. getsockopt(), optlen is a value--resultparameter, initially set to the
  5078.  
  5079.  
  5080. 62    Section 3.4                  AmiTCP/IP                   System Manual
  5081.  
  5082.  
  5083.  
  5084. size of the storage area pointed to by optval, and modified upon return
  5085. to indicate the actual amount of storageused.
  5086.    An example should help clarify things.  It is sometimes useful to
  5087. determine the type (e.g., stream, datagram, etc.)   ofan existing socket;
  5088. programs under inetd (described in section 3.4.8) may need to perform
  5089. this task.  This can be accomplished as follows via theSO _TYPE socket
  5090. option and the getsockopt() call:
  5091.  
  5092.  
  5093.     #include <sys/types.h>
  5094.     #include <sys/socket.h>
  5095.  
  5096.  
  5097.     long type, size;
  5098.  
  5099.  
  5100.     size = sizeof (type);
  5101.  
  5102.  
  5103.     if (getsockopt(s, SOL_SOCKET, SO_TYPE, (char *) &type, &size) < 0) -
  5104.           ...
  5105.     "
  5106.  
  5107.  
  5108. After the getsockopt() call, type will be set to the value of the socket
  5109. type, as defined in sys/socket.h.  If, for example, thesocket were a
  5110. datagram socket, type would have the value corresponding to SOCK_DGRAM.
  5111.  
  5112.  
  5113.  
  5114. 3.4.8   Inetd
  5115.  
  5116. One of the daemons provided with AmiTCP/IP is inetd, the so called
  5117. ``internet super--server.''  Inetd is invoked at start-up time, and
  5118. determines the servers, for which it isto listen, from the file
  5119. AmiTCP:db/inetd.conf15.  Once this information has been read and a
  5120. pristine environment created, inetd proceeds to create one socket for
  5121. each service it is to listen for, binding the appropriate port number to
  5122. each socket.
  5123.    Inetd then performs a select() on all these sockets for read
  5124. availability, waiting for somebody wishing a connection to the service
  5125. corresponding to that socket.  Inetd then performs an accept() on the
  5126. socket in question, releases the socketwith a ReleaseSocket() call and
  5127. starts the appropriate server.
  5128.    Servers making use of inetd are considerably simplified, as inetd takes
  5129. care of the majority of the work required in establishing a connection.
  5130. The server invoked by inetd expects thesocket connected to its client to
  5131. be found by calling ObtainSocket().  The client socketID for the server
  5132. is found in a DaemonMessage structure given to the server process.
  5133. Usually the netlib:autoinitd.o module takes care of obtaining the client
  5134. socket into global variable server_socket.  For practical purposes the
  5135. code might assume this socket to be 0.
  5136.    One callwhich may be of interest to individuals writing servers under
  5137. inetd is the getpeername() call, which returns the address of the peer
  5138. (process) connected on the other end ofthe socket.   For example, to log
  5139. the Internet address in ``dot notation''(e.g., ``128.32.0.4'') of a
  5140. ________________________________
  5141.   15In UNIX systems /etc/inetd.conf.
  5142.  
  5143.  
  5144. System Manual                   AmiTCP/IP                   Section 3.5    63
  5145.  
  5146.  
  5147.  
  5148. client connected to a server under inetd, the following code might be
  5149. used:
  5150.  
  5151.     struct sockaddr_in name;
  5152.     int namelen = sizeof (name);
  5153.      ...
  5154.     if (getpeername(0, (struct sockaddr *)&name, &namelen) < 0) -
  5155.          syslog(LOG_ERR, "getpeername: %m");
  5156.          exit(1);
  5157.     " else
  5158.          syslog(LOG_INFO, "Connection from %s", inet_ntoa(name.sin_addr));
  5159.      ...
  5160.  
  5161. While the getpeername() call is especially useful when writing programs
  5162. to run with inetd, it can be used underother circumstances.
  5163.    Sources for a very simple TCP protocol server is included with
  5164. AmiTCP/IP as an example.
  5165.  
  5166.  
  5167.  
  5168. 3.5     Deviation  From  Berkeley  Sockets
  5169.  
  5170.  
  5171. This section discusses the differences between the API of the AmiTCP/IP
  5172. and the 4.3BSD. They are not so numerousas it might seem to, but worth
  5173. taking attention to when porting existing 4.3BSD software to AmiTCP/IP.
  5174.  
  5175.  
  5176.  
  5177. 3.5.1   Opening and Closing the Shared Library
  5178.  
  5179. Since the API is provided as a shared library, it must be opened to be
  5180. able to access the functions it provides.   Note that any two tasks may
  5181. not share a socket library base, since the base contains task specific
  5182. information.
  5183.    AmiTCP/IPdoes resource tracking based on the information stored in a
  5184. library base, so it is essential that the library is closed after use,
  5185. since the resources used by the base aregone if the application exits
  5186. without closing the base.
  5187.    See section 3.1.2 for examples and more discussion on the subject.
  5188.  
  5189.  
  5190.  
  5191. 3.5.2   Naming Conventions of the API Functions
  5192.  
  5193. The API functions which preserve the semantics of the BSD calls are named
  5194. the same as the original functions.  In the name of binary compatibility
  5195. between different C compilers the functions which either take a structure
  5196. as an argument or return a structure asa value had to be changed not to
  5197. do so.  These functions are named differently; all words in these
  5198.  
  5199. function names begin with an upper caseletter.   Inlinefunctions16  are
  5200. provided with the original semantics, however.   This makes it possible to
  5201. keep using the original functions when writing the code and still be
  5202. binary compatible.  The inline functions are mostly trivial; for example
  5203. the select() call is actually an inlinewhich calls WaitSelect() with
  5204. last argument as NULL.
  5205. ________________________________
  5206.   16Or linker stubs in compilers with no inline functions.
  5207.  
  5208.  
  5209. 64    Section 3.5                  AmiTCP/IP                   System Manual
  5210.  
  5211.  
  5212.  
  5213.    This is amatter which should be totally invisible for C users, but
  5214. assembler programmers should take attention and be sure to pass arguments
  5215. as described in the function reference for the non-inline versions.
  5216.  
  5217.  
  5218.  
  5219. 3.5.3   errno
  5220.  
  5221.  
  5222. Unix libraries return error values in aglobal variable named errno.
  5223. Since a shared library cannot know the address of any variables of an
  5224. application, the address of the errno must be explicitly told to the
  5225. AmiTCP/IP. An alternative is to use Errno() call to fetch the error
  5226. value, but since the first method needsno modifications to the existing
  5227. sources (besides calling SetErrnoPtr() once in the beginning), it is the
  5228. preferred method.  Section 3.1.2 contains examples andmore discussion
  5229. about the matter.
  5230.  
  5231.  
  5232.  
  5233. 3.5.4   NewField in the sockaddr Structures
  5234.  
  5235.  
  5236. Since AmiTCP/IP is based on the BSD Net/2 release, it has few
  5237. differences to the 4.3BSD. Most notableone is that the sockaddr and
  5238. sockaddr_in structureshave a new field telling the length of the
  5239. structure.  These are named as sa_len and sin_len respectively.   These
  5240. fields are used by the AmiTCP/IP to determine the real length of the
  5241. address given.
  5242.    In addition the sockaddr_in structure has a field named sin_zero, which
  5243. should be initialized to zero before passed to the AmiTCP/IP, since any
  5244. garbage left there will be used by the routing facility (which obviously
  5245. leads to undesired behaviour).
  5246.  
  5247.  
  5248.  
  5249. 3.5.5   Linger  Time
  5250.  
  5251.  
  5252. The unit of the linger time of a socketis a second.   The Net/2 code
  5253.  
  5254. seemed to use ticks17.
  5255.  
  5256.  
  5257.  
  5258. 3.5.6   Transferring Sockets from a Task to Another
  5259.  
  5260.  
  5261. Since AmigaOS has no fork() call, in which the child process inherits the
  5262. file descriptors, and hence sockets, a mechanism for transferring sockets
  5263. from a task to another must be provided.  This is accomplished by the
  5264. calls ReleaseSocket(), ReleaseCopyOfSocket() and ObtainSocket(), which
  5265. release a socket, a copy of a socket andobtain a released socket,
  5266. respectively.  An id is given to a socket placed in thelist of released
  5267. sockets.  This id can be either unique or be based on aservice number in
  5268. cases where it is irrelevant which instance of the server process for the
  5269. service in question obtains the socket.  If an unique id is used, the
  5270. releasing task is responsible of transferring the id to the obtaining
  5271. task.
  5272. ________________________________
  5273.   17One tick is 1/hz:th of a second, where hz is the frequency of the
  5274.  
  5275. electricity of the wall socket.
  5276.  
  5277.  
  5278. System Manual                   AmiTCP/IP                   Section 3.5    65
  5279.  
  5280.  
  5281.  
  5282.    This feature affects the server processes only, since the clients
  5283. usually create the socket(s) on their own.
  5284.  
  5285.  
  5286.  
  5287. 3.5.7   Ioctl  Differences
  5288.  
  5289. The Unix ioctl() function is renamed asIoctlSocket() in AmiTCP/IP to
  5290. avoid name clashes with some C runtime libraries.
  5291.    Followingsummarizes other differences in the ioctl calls:
  5292.  
  5293.  1. FIOCLEX and FIONCLEX are silently ignored, that is, they are
  5294.     accepted, but have no effect.  Whether sockets should be closed on
  5295.     exec() or not is irrelevant, since AmigaOS has no such feature (see
  5296.     discussion about fork() above).
  5297.  
  5298.  2. FIOSETOWN and SIOCSPGRP take a pointer to a struct Task * as an
  5299.     argument instead of a pointer to a process (or group) id.  Note that
  5300.     if the task in question has not opened the bsdsocket.library the
  5301.     owner of the precess is set to NULL (disabled).  The task pointer is
  5302.     used as the receiver of the asynchronous notification signals if
  5303.     asynchronous notification is enabled.
  5304.  
  5305.  3. FIOGETOWN and SIOCGPGRP take a pointer to a struct Task * as an
  5306.     argument in which the current task pointer of the owner of the socket
  5307.     in question is placed on return.
  5308.  
  5309.  
  5310.  
  5311. 3.5.8   Signal  Handling
  5312.  
  5313. There is a fundamental difference between BSD Unix and Amiga signal
  5314. handling and the system call interface.  In the Unix systems a received
  5315. signal may interrupt a process executinga system call.  If there is a
  5316. signal handler installed, it can be executed before the system call
  5317. returns to the main execution branch with an error code.
  5318.    However,there are some system calls which may not be interrupted.  If
  5319. a Unix process has a negative priority,tsleep() does not wake up until
  5320. the specified condition is met.
  5321.    The interrupted system call does not have any unrecoverable effects,
  5322. the execution of the program may continue after the errno is checked
  5323. against other errors than EINTR.
  5324.    In the AmigaOS, Exec, there are no specific system calls.  All OS
  5325. functions are provided by shared libraries.   There areeither no separate
  5326. kernel and user memory spaces, the one common memory space is shared by
  5327. all processes.  The IO system is based on messages, which are implemented
  5328. as shared memory areas.  When a program receives a message to a port, it
  5329. is delivered a signal associated with the port.
  5330.    While itis possible to use signal handlers with Exec, they are even
  5331. more dangerous to use and restricted than in Unix systems.  This is not
  5332. recommended, since the exception handlermust behave like any real
  5333. interrupt handler.  Calls provided by AmiTCP/IP are notcallable from
  5334. interrupts.  Further, it is not possible to interrupt asystem call
  5335. implemented as a shared library function.
  5336.    The application must itself react on receipt of the signals.  The
  5337. recommended way of handling these signals is by the normal Wait() of by
  5338.  
  5339.  
  5340. 66    Section 3.5                  AmiTCP/IP                   System Manual
  5341.  
  5342.  
  5343.  
  5344. AmiTCP/IP call WaitSelect(), which allows an application to specify a
  5345. signal mask which should abort the selection.   The application then
  5346. checks the received signals and calls appropriate handler for the signal.
  5347.  
  5348.  
  5349.  
  5350. 3.5.9   Asynchronous I/O
  5351.  
  5352.  
  5353. AmigaOS does not have any reserved signals for networking, such as SIGIO
  5354. or SIGURG in Unix systems, and so the scheme used in asynchronous
  5355. notification must be changed a little.
  5356.    The application can set a group of signal masks, with function named
  5357. SetSocketSignals(), to be used by the AmiTCP/IP. First argument
  5358. specifies the signal mask which should break the blocking of the blocking
  5359. socket calls.  It is by default set to the signal for CTRL-C. Second
  5360. argument specifies the signal(s) to be sent when asynchronous
  5361. notification for readiness to read is necessary.   Thismask lets the
  5362. application define which signal should be used as replacement for SIGIO
  5363. signal of the Unix systems.  Third and last argument specifies the
  5364. corresponding mask for the asynchronousnotification of urgent
  5365. (out-of-band) data (SIGURG). These lasttwo masks are zero by default.
  5366.    Note thatthere is no way to query the current settings of these
  5367. signals form the AmiTCP/IP, so the application must store the signal
  5368. numbers (or masks) for later use.  Also note that the break mask must be
  5369. explicitly given if SetSocketSignals() is called, since the values
  5370. supplied override the default settings.
  5371.  
  5372.  
  5373.  
  5374. 3.5.10   Constructing an Event Loop
  5375.  
  5376.  
  5377. Amiga programs are often constructed around an event loop, in which
  5378. Wait() function is used to wait for somesubset of given signals to
  5379. arrive.  When a signal is received, some actions are taken and if IO is
  5380. performed, it is usually asynchronous.
  5381.    Many Unixprograms use to do synchronous IO and let the signal handlers
  5382. to handle special events (window size changes, timeouts, etc.).  This can
  5383. be emulated to some extent with AmigaOS,since it is possible to specify
  5384. an exeption function to handle receptionof given signals.  This is very
  5385. limited, though, since the exeption codeis executed at true interrupt
  5386. level, and may thus pre-empt the main process in an arbitrary location.
  5387. Also note that a very limited set of shared library functions can be
  5388. called while in interrupt, especially note that any AmiTCP/IP function
  5389. may NOT be called from interrupt code.
  5390.    AmiTCP/IPoffers remedy for this, however.  The application can use
  5391. WaitSelect() to handle both Amiga signals and socket IO multiplexing.
  5392.  
  5393. Selecting assures that the following socket calls will not block18.
  5394.    Another possiblility is to use signal driven socket IO (see section
  5395. 3.4.3).
  5396.    Yet another possibility is to specify a special break mask with
  5397. SetSocketSignals() function.  The signals in the mask cause any blocking
  5398. socket IO routine to return with the error code EINTR. Note that the
  5399. ________________________________
  5400.   18See NOTES section of the reference for the WaitSelect().
  5401.  
  5402.  
  5403. System Manual                   AmiTCP/IP                   Section 3.5    67
  5404.  
  5405.  
  5406.  
  5407. signals are not cleared in this procedure.   The Wait()with the same
  5408. signal mask can be used to determine (and clear) the received signals.
  5409. This allows the usage of synchronous socket IO, but the EINTR error code
  5410. must be checked after each failing call.
  5411.  
  5412.  
  5413.  
  5414. 3.5.11   ''Killing'' the Processes
  5415.  
  5416. In AmigaOS the applications must co-operate with the OS for the user to
  5417. be able to stop them.  This is why the blocking operations of the
  5418. AmiTCP/IP can be aborted.  By default the reception ofCTRL-C signal
  5419. aborts any blocking call.  The call returns an error value (in errno) of
  5420. EINTR when aborted.  In addition the signal which caused the break will
  5421. remain set for the application to be able to react on it in its normal
  5422. event processing.  This means that the application neednot specially
  5423. check for EINTR after every socket callas long as they eventually check
  5424. for the break signal.
  5425.    All sockets left open by the application are closed by the
  5426. CloseLibrary() call.  You may left the sockets open when aborting the
  5427. program, because the socket library is closed automatically during the
  5428. exit process if either autotermination function (specific to SAS C) or
  5429. ANSI atexit() function is installed before the exit is done.  .
  5430.    The signals which cause the abort can be set with the
  5431. SetSocketSignals() call.  The break signal mask is given as the first
  5432. argument.  Calling this function discards the previousvalues of the
  5433. sockets signal masks.  Aborting can be disabled by giving the mask as 0L.
  5434. See section 3.5.9 for more discussion about the SetSocketSignals() call.
  5435.  
  5436.  
  5437.  
  5438. 3.5.12   WaitSelect()
  5439.  
  5440. In AmiTCP/IP no other than socket I/O can be multiplexed with the
  5441. select() call.  This may be a major pain as I/O is normally multiplexed
  5442. with an Wait() loop, waiting for given signals to arrive.  This is the
  5443. motivation for the WaitSelect() call.  It combines theselection and
  5444. waiting in a single call19.  The WaitSelect() takes one argument in
  5445. addition to the normal select() call.  It is a pointerto signal mask to
  5446. wait for in addition to the signals thatthe AmiTCP/IP uses internally.
  5447. If any of these signals is received, they are returned as a result in the
  5448. same signal mask.  Signals specified in the given signal mask override
  5449. the signals of the break mask (see previous section).  If the same signal
  5450. is specified in both the SIGINTR mask and the mask given to the WaitSelect(),
  5451. the reception of the signal causes it tobe cleared and returned in the mask
  5452. as the result.
  5453.    WaitSelect() can be used as replacement for the Wait() in applications
  5454. which require to multiplex both socket related and other Amiga I/O.
  5455.  
  5456.  
  5457.  
  5458. ________________________________
  5459.   19This feature was really easy to implement, since AmiTCP/IP uses a Wait()
  5460.  
  5461. to wait for I/O events itself.
  5462.  
  5463.  
  5464. 68    Section 3.5                  AmiTCP/IP                   System Manual
  5465.  
  5466.  
  5467.  
  5468.  
  5469.  
  5470. Chapter 4
  5471.  
  5472.  
  5473.  
  5474. Internal Description
  5475.  
  5476.  
  5477.  
  5478. 4.1     Source  File  Structure
  5479.  
  5480.  
  5481. The source tree of AmiTCP/IP is dividedto few main parts:
  5482.  
  5483.  
  5484.  1. Directory sys contains BSD Unix system header files, which are ported
  5485.     to the Amiga environment.
  5486.  
  5487.  
  5488.  2. Directory net contains modules for the general networking services.
  5489.     They are independent of any particular protocol family.
  5490.  
  5491.  
  5492.  3. Directory netinet contains the modules for the internet (inet)
  5493.     protocol family.  IP, ICMP, TCP and UDP are internet protocols.
  5494.  
  5495.  
  5496.  4. Directory kern contains modules, which provide the BSD kernel
  5497.     environment for the networking routines.
  5498.  
  5499.  
  5500.  5. Directory api contains the BSD socket compatible shared library API
  5501.     code.
  5502.  
  5503.  
  5504.    The filesare briefly described in the following paragraphs.  Note that
  5505.  
  5506. some of the header files are actually located to the NETINCLUDE:1
  5507. directory.
  5508.  
  5509.  
  5510.  
  5511. 4.1.1   System Include Files
  5512.  
  5513.  General Headers
  5514.  
  5515.  
  5516.     sys/cdefs.h  Definitions to harmonize various C language dialects.
  5517.  
  5518.     sys/param.h  General machine independent parameter definitions.
  5519.  
  5520.     sys/time.h  Definition of structure timeval.
  5521.  
  5522.     sys/types.h  Common C type definitions and file descriptorset macros
  5523.         for select().
  5524.  
  5525.  
  5526.  BSD Socket API
  5527. ________________________________
  5528.    1See section 3.1.3 on page 30.
  5529.  
  5530.  
  5531.  
  5532.                                       69
  5533.  
  5534.  
  5535. 70    Section 4.1                  AmiTCP/IP                   System Manual
  5536.  
  5537.  
  5538.  
  5539.     sys/errno.h  Error code definitions for system functions.
  5540.  
  5541.     sys/ioctl.h  Definitions for socket IO control.
  5542.  
  5543.     sys/socket.h  Definitions related to sockets:  types, address
  5544.         families, options and prototypes.
  5545.  
  5546.     sys/uio.h  IO structure definition for sendmsg() and recvmsg()2.
  5547.  
  5548.  
  5549.  BSD Kernel Data Structures
  5550.  
  5551.  
  5552.     sys/domain.h  Domain structure and global domain pointer declarations.
  5553.  
  5554.     sys/kernel.h  Global kernel variable definitions (used throughoutthe
  5555.         kernel).
  5556.  
  5557.     sys/malloc.h  Defines the bsd_malloc() and bsd_free() functions.
  5558.  
  5559.     sys/mbuf.h  Mbuf structure definition and inline macros.
  5560.  
  5561.     sys/protosw.h  Protocol switch structure definition with related
  5562.         definitions (options, actions, etc.).
  5563.  
  5564.     sys/queue.h  General queue data structures.
  5565.  
  5566.     sys/socketvar.h  Socket structure definition and related utility
  5567.         macros.
  5568.  
  5569.     sys/synch.h  Declarations for tsleep and spl functions.
  5570.  
  5571.     sys/syslog.h  Logging related definitions.
  5572.  
  5573.     sys/systm.h  System wide definitions and prototypes.
  5574.  
  5575.  
  5576.  
  5577. 4.1.2   Protocol Independent Network Routines
  5578.  
  5579.  Network Interface
  5580.  
  5581.  
  5582.     net/if.c  General network interface routines.
  5583.  
  5584.     net/if.h  Defines the interface for network adapter drivers.
  5585.  
  5586.     net/if_arp.h  General protocol independent ARP structures.
  5587.  
  5588.     net/if_dl.h  Defines the Link Level sockaddr structure.
  5589.  
  5590.     net/if_loop.c  Loopback device routines.
  5591.  
  5592.     net/if_sana.c  Interface module for the SANA-IInetwork adapter
  5593.         drivers.
  5594.  
  5595.     net/if_sana.h  Defines the interface for the SANA-II network adapter
  5596.         drivers.
  5597.  
  5598.     net/if_types.h  Interface type numbers.  Obsolete.
  5599.  
  5600.     net/netisr.h  and
  5601.  
  5602.     net/netisr.c  Defines the network input queue scheduling routines.
  5603.  
  5604.     net/sana2arp.c  ARP routines for Sana-II devices.
  5605.  
  5606.     net/sana2arp.h  SANA-II private ARP headers.
  5607.  
  5608.     net/sana2copybuff.c   Buffer management routines called from SANA-II
  5609. ________device_driver.__________
  5610.  
  5611.    2These functions are not implemented in this release of the AmiTCP/IP
  5612.  
  5613.  
  5614. System Manual                   AmiTCP/IP                   Section 4.1    71
  5615.  
  5616.  
  5617.  
  5618.     net/sana2errno.h  SANA-II error lists and printing header.
  5619.  
  5620.     net/sana2request.c   Moduleto handle SANA-II IO Requests.
  5621.  
  5622.     net/sana2request.h   Inlineroutines to manage different SANA-II IO
  5623.         requests.
  5624.  
  5625.     net/sana2tags.c  Common customization parameters for the sana_softc
  5626.         network interface.
  5627.  
  5628.     net/sana2tags.h  Defines the tags to customize sana_softc network
  5629.         interface.
  5630.  
  5631.     netlib:sana2perror.c   Printing routines for SANA-II error messages.
  5632.  
  5633.  
  5634.  Routing
  5635.  
  5636.  
  5637.     net/radix.c  Routines for searching, adding and removing data items in
  5638.         the radix binary tree.
  5639.  
  5640.     net/radix.h  Defines the radix tree data structures.
  5641.  
  5642.     net/route.c  General, protocol independent routing functions.
  5643.  
  5644.     net/route.h  Defines data structures for routing entries,tables and
  5645.         statistics.
  5646.  
  5647.     net/rtsock.c  The socket interface to the routing information.
  5648.  
  5649.  
  5650.  Raw Sockets
  5651.  
  5652.  
  5653.     net/raw_cb.c  Routines to manage the rawprotocol control blocks.
  5654.  
  5655.     net/raw_cb.h  The raw protocol control block definition.
  5656.  
  5657.     net/raw_usrreq.c  The raw socket interface to the low level protocols
  5658.         and network adapters.
  5659.  
  5660.  
  5661.  
  5662. 4.1.3   Internet Protocol Modules
  5663.  
  5664.  Inet Domain
  5665.  
  5666.  
  5667.     netinet/in.c  Generic Internet addressing routines.
  5668.  
  5669.     netinet/in.h  Protocol numbers, port conventions, inet address
  5670.         definitions.
  5671.  
  5672.     netinet/in_cksum.c  Calculates checksum for internet protocol headers.
  5673.  
  5674.     netinet/in_pcb.c  Generic internet protocol routines, binding,
  5675.         addressing.
  5676.  
  5677.     netinet/in_pcb.h  Declares generic internet protocol control block.
  5678.  
  5679.     netinet/in_proto.c  Defines internet protocol control blocks.
  5680.  
  5681.     netinet/in_systm.h  Some network byte order type definitions.
  5682.  
  5683.     netinet/in_var.h  Define an interface address structure for internet.
  5684.  
  5685.  
  5686.  IP, ICMP
  5687.  
  5688.  
  5689.     netinet/icmp_var.h  ICMP statistics.
  5690.  
  5691.     netinet/ip.h  IP packet header, packet options, timestamp.
  5692.  
  5693.  
  5694. 72    Section 4.1                  AmiTCP/IP                   System Manual
  5695.  
  5696.  
  5697.  
  5698.     netinet/ip_icmp.c  Routines to generate, receive and reflect ICMP
  5699.         packets.
  5700.  
  5701.     netinet/ip_icmp.h  ICMP packet structure.
  5702.  
  5703.     netinet/ip_input.c  IP input, packet reassemble and packet forwarding.
  5704.  
  5705.     netinet/ip_output.c  IP output, packet fragmenting.
  5706.  
  5707.     netinet/ip_var.h  Define IP statistics, external IP packet header,
  5708.         reassemble queues structures.
  5709.  
  5710.     netinet/raw_ip.c  Provide a raw interface to the IP protocol.
  5711.  
  5712.  
  5713.  TCP
  5714.  
  5715.  
  5716.     netinet/tcp.h  Define the TCP packet structure.
  5717.  
  5718.     netinet/tcp_debug.c  TCP debugging routines.
  5719.  
  5720.     netinet/tcp_debug.h  Header for TCP debugging.
  5721.  
  5722.     netinet/tcp_fsm.h  TCP Finite State Machine states.
  5723.  
  5724.     netinet/tcp_input.c  TCP input routines.
  5725.  
  5726.     netinet/tcp_output.c  TCP output routines.
  5727.  
  5728.     netinet/tcp_seq.h  TCP sequence numbering.
  5729.  
  5730.     netinet/tcp_subr.c  Various TCP subroutines for initializing,
  5731.         connection maintenance etc.
  5732.  
  5733.     netinet/tcp_timer.c  TCP timeout routines.
  5734.  
  5735.     netinet/tcp_timer.h  TCP timing constants.
  5736.  
  5737.     netinet/tcp_usrreq.c  Process TCP user requests (send, timeout),
  5738.         attach, disconnect.
  5739.  
  5740.     netinet/tcp_var.h  Define TCP control block and TCP statistics.
  5741.  
  5742.     netinet/tcpip.h  Define the overlaid TCPIP packet header structure.
  5743.  
  5744.  
  5745.  UDP
  5746.  
  5747.  
  5748.     netinet/udp.h  Define the UDP packet structure.
  5749.  
  5750.     netinet/udp_usrreq.c  Routines to UDP output, input and notification.
  5751.  
  5752.     netinet/udp_var.h  Define UDPIP packet overlay, UDP statistics.
  5753.  
  5754.  
  5755.  
  5756. 4.1.4   BSDKernel Service Modules
  5757.  
  5758.  BSD Kernel Support
  5759.  
  5760.  
  5761.     kern/amiga_includes.h   Include file which includes all amiga specific
  5762.         include files.
  5763.  
  5764.     kern/amiga_main.c  Main module of the AmiTCP/IP.
  5765.  
  5766.     kern/amiga_subr.h  Miscellaneous function definitions (usually short
  5767.         inline functions).
  5768.  
  5769.     kern/amiga_time.c  Timer module for the timeout functions.
  5770.  
  5771.     kern/amiga_time.h  Amiga timer.device related functions.
  5772.  
  5773.  
  5774. System Manual                   AmiTCP/IP                   Section 4.1    73
  5775.  
  5776.  
  5777.  
  5778.     kern/kern_malloc.c  Malloc & free related functions.
  5779.  
  5780.     kern/kern_synch.c  tsleep and spl function definitions.
  5781.  
  5782.     kern/uipc_mbuf.c  Mbuf functions.
  5783.  
  5784.  
  5785.  Socket Level Functions
  5786.  
  5787.  
  5788.     kern/uipc_domain.c  Domain functions, especially pfslowtimo() and
  5789.         pffasttimo().
  5790.  
  5791.     kern/uipc_socket.c  Higher level so-level functions (socreate(),
  5792.         sobind() etc.).
  5793.  
  5794.     kern/uipc_socket2.c  Lower level so-level functions (soisconnecting(),
  5795.         soqremque(), sowakeup() etc.).
  5796.  
  5797.  
  5798.  NETTRACE Maintenance Process Support
  5799.  
  5800.  
  5801.     kern/amiga_config.c  Configuration and ARexx command support routines.
  5802.  
  5803.     kern/amiga_config.h  Defines the structure for configuration
  5804.         variables.
  5805.  
  5806.     kern/amiga_cstat.c  Query support routines.
  5807.  
  5808.     kern/amiga_log.c  Functions for initialization of log task and code
  5809.         for task itself.
  5810.  
  5811.     kern/amiga_log.h  Header file for logging functions.
  5812.  
  5813.     kern/amiga_netdb.c  Network database parsing and support functions.
  5814.  
  5815.     kern/amiga_netdb.h  Declares the network database structures and
  5816.         types.
  5817.  
  5818.     kern/amiga_rexx.c  Arexx-interface.
  5819.  
  5820.     kern/amiga_rexx.h  Arexx-interface definitions.
  5821.  
  5822.     kern/config_var.awk  Awk script to generate both code and
  5823.         documentation from the file kern/variables.src.
  5824.  
  5825.     kern/subr_prf.c  Interfaces for (s)printf(), panic() and log()
  5826.  
  5827.     kern/variables.src   Definition and documentation for configuration
  5828.         variables
  5829.  
  5830.  
  5831.  
  5832. 4.1.5   BSDSocket API
  5833.  
  5834.  Shared Library Interface
  5835.  
  5836.  
  5837.     api/allocdatabuffer.c   Client data buffer allocation functions.
  5838.  
  5839.     api/allocdatabuffer.h   Client data buffer allocation definitions.
  5840.  
  5841.     api/amiga_api.c  Contains API initialization and deinitialization
  5842.         functions and data.  Opening and Closing of the AmiTCP/IP socket
  5843.         library bases.
  5844.  
  5845.     api/amiga_api.h  Description of the SocketBase structure (forinternal
  5846.         AmiTCP/IP use only), and some inline functions relatedto the API
  5847.         functionality.
  5848.  
  5849.  
  5850. 74    Section 4.1                  AmiTCP/IP                   System Manual
  5851.  
  5852.  
  5853.  
  5854.     api/amiga_libcallentry.h   Included in every module which defines
  5855.         AmiTCP/IP socket library calls.
  5856.  
  5857.     api/amiga_libtables.c   Exec library base list and AmiTCP/IP socket
  5858.         library function tables for MakeLibrary().
  5859.  
  5860.     api/amiga_raf.h  Compiler dependent macros for Register Argument
  5861.         Functions.
  5862.  
  5863.     api/apicalls.h  Includes either api/apicalls_gnuc.h or
  5864.         api/apicalls_sasc.h.
  5865.  
  5866.     api/apicalls_gnuc.h  Inline functions for internal API calls for GNUC.
  5867.  
  5868.     api/apicalls_sasc.h  Inline functions for internal API calls for SASC.
  5869.  
  5870.  API Functions
  5871.  
  5872.     api/amiga_generic.c  General Unix system calls related to file
  5873.         descriptors ported for AmiTCP/IP socket library.  There are also
  5874.         some Amiga specific extensions to the BSD Unix system calls in
  5875.         this module.
  5876.  
  5877.     api/amiga_libcalls.c  Inet library functions (link library in Unix
  5878.         system).  These inet functions are provided as a part of the
  5879.         AmiTCP/IP socket library.
  5880.  
  5881.     api/amiga_syscalls.c  Standard BSD style socket functions ported to
  5882.         the AmiTCP/IP socket library.
  5883.  
  5884.     api/gethostnamadr.c   Functions that calls resolver in order to obtain
  5885.         host information from nameserver.  Calls netdatabase functions if
  5886.         information can not be resolved.
  5887.  
  5888.     api/gethtbynamadr.h   Prototypes for two functions in api/getxbyy.h.
  5889.  
  5890.     api/getxbyy.c  Host (without nameserver), network, service ja protocol
  5891.         query functions (also a link library in unix system).
  5892.  
  5893.     api/hostbuf.h  Structure definition for host queries and few minor
  5894.         netdb stuff.
  5895.  
  5896.  Resolver Functions
  5897.  
  5898.     api/arpa_nameser.h  Information for nameserver query.
  5899.  
  5900.     api/res_comp.c  Routines to translate domain names between
  5901.         conventional ascii and the compressed format used in queries.
  5902.  
  5903.     api/res_debug.c  Functions that output debugging information3
  5904.  
  5905.     api/res_init.h  Resolver initializer function.  Very simple in
  5906.         AmiTCP/IP implementation.
  5907.  
  5908.     api/res_mkquery.c  Function that forms a domain name query in buffer.
  5909.  
  5910.     api/res_query.c  Functions to generate query sequence and append
  5911.         domains to incomplete hostnames.
  5912.  
  5913.     api/res_send.c  Function to send and receive query to and from a
  5914.         nameserver, respectively.
  5915.  
  5916.     api/resolv.h  Resolver datatypes, defines, variables and prototypes.
  5917. ________________________________
  5918.    3If RES_DEBUG defined at compile time
  5919.  
  5920.  
  5921. System Manual                   AmiTCP/IP                   Section 4.2    75
  5922.  
  5923.  
  5924.  
  5925. 4.1.6   Miscellaneous Files
  5926.  
  5927.  
  5928.  Makefiles
  5929.  
  5930.  
  5931.     GCCOPTS  Compiler options forthe GCC.
  5932.  
  5933.     GNUmakefile  Makefile used with GNU make in HP-UX workstations, where
  5934.         the source tree is maintained.
  5935.  
  5936.     SCOPTIONS  Compiler options for the SAS/C 6.x
  5937.  
  5938.     Smakefile  Makefile for SAS/C smake 6.x to compile the AmiTCP/IP.
  5939.  
  5940.  
  5941.  Revision Support
  5942.  
  5943.  
  5944.     bsdsocket.library_rev.rev   Contains revision numberof the current
  5945.         version (number of the latest build).  This file is updated with
  5946.  
  5947.         the BumpRev utility4.
  5948.  
  5949.     bsdsocket.library_rev.h   Automaticallygenerated by BumpRev.  Contains
  5950.         build date, version and revision strings.
  5951.  
  5952.  
  5953.  SAS/C 6.x GST Support
  5954.  
  5955.  
  5956.     all_includes.c  C file for GST generation.  Just includes the
  5957.         all_includes.h file.
  5958.  
  5959.     all_includes.h  Includes all header files needed by theAmiTCP/IP,
  5960.         which are suitable for inclusion in a GST. Note that any headers
  5961.         with inline functions can not be included in a GST.
  5962.  
  5963.  
  5964.  Other Files
  5965.  
  5966.  
  5967.     conf/conf.h  Static configuration information in form of preprocessor
  5968.         defines.  Every C module must include this as the first include
  5969.         file.
  5970.  
  5971.     conf/rcs.h  RCS header inclusion macro for GCC. InSAS/C this macro is
  5972.         defined in the SCOPTIONS file.
  5973.  
  5974.     protos/*/*.h  Prototypes for functions in various modules.
  5975.  
  5976.  
  5977.  
  5978. 4.2     AmiTCP/IP Initialization
  5979.  
  5980.  
  5981. All more or less distinct modules of theAmiTCP/IP must be initialized
  5982. before they can be used for the real work.   Initialization is done in
  5983. module kern/amiga_main.c, which definesfunctions init_all() and
  5984. deinit_all().  The main() function calls the init_all()after it has done
  5985. all needed local initializations.  If init_all() failsthe deinit_all() is
  5986. called to clean up.
  5987.  
  5988. ________________________________
  5989.    4The BumpRev is supplied by Commodore.
  5990.  
  5991.  
  5992. 76    Section 4.2                  AmiTCP/IP                   System Manual
  5993.  
  5994.  
  5995.  
  5996. 4.2.1   init _all()
  5997.  
  5998. This function calls the initialization routines of all modules which have
  5999. such.  This must be done carefully in the correct partial order.
  6000.    There arefew general heuristics which can be applied on initialization
  6001. (with respect to the ordering requirements):
  6002.  
  6003.  
  6004.  1. Initialize the modules for which the initialization cannot fail.
  6005.     This includes semaphore initializations and such.
  6006.  
  6007.  2. Initialize the modules which are most likely to fail, e.g.  large
  6008.     memory allocations, modules which require recent versions of some
  6009.     libraries etc.
  6010.  
  6011.  3. Initialize modules left over by rules 1 and 2.
  6012.  
  6013.  
  6014.    Semaphoreinitializations are first, because later steps may use them
  6015. to protect against race conditions.
  6016.    The initialization process of the AmiTCP/IP is fully reversible.  If
  6017. the initialization fails in any step thedeinit _all() function can be
  6018. used to collect the garbage.
  6019.    init_all() does the initializations in following order, returning
  6020. nonzero if all steps succeed.  Numbers in the parenthesis are the section
  6021. and page numbers for more information, respectively:
  6022.  
  6023.  
  6024.  1. malloc_init() initializes the malloc_semaphore.  This is first since
  6025.     later steps may want to use bsd_malloc() to allocatememory (5.2.2,
  6026.     95).
  6027.  
  6028.  2. spl_init() initializes the priority level subsystem,which is used
  6029.     throughout the code to protect critical sections (5.3.1, 96).
  6030.  
  6031.  3. sleep_init() initializes the sleep_semaphore and the sleep queues
  6032.     (5.3.2, 97).
  6033.  
  6034.  4. readconfig() reads in and parses the command line arguments and the
  6035.     configuration file.  This is the first phase which is expected to
  6036.     fail.  This is done at the beginning in order to allow other
  6037.     initialization functions to use the configuration information given.
  6038.     Note that since the logging subsystem is not initialized yet,
  6039.     readconfig() cannot log any errors encountered (4.11, 91).
  6040.  
  6041.  5. log_init() initializes the logging subsystem.  From now on other
  6042.     initialization functions can log needed error messages (4.8, 89).
  6043.  
  6044.  6. mbinit() allocates memory to be used by the protocols.  This is a
  6045.     candidate to fail if the memory is nearly exhausted (4.5, 79).
  6046.  
  6047.  7. timer_init() initializes the timeout module.  This requires version
  6048.     36 or greater of the operating system.  Returns the signal mask to
  6049.     wait for the timeout messages (5.1, 93).
  6050.  
  6051.  8. api_init() initializes and creates the master socketbase structure
  6052.     (4.10.2, 91).
  6053.  
  6054.  9. res_init() initializes resolver structure and semaphore.
  6055.  
  6056.  
  6057. System Manual                   AmiTCP/IP                   Section 4.3    77
  6058.  
  6059.  
  6060.  
  6061. 10. sana_init() initializes the SANA-II network interface module.   This
  6062.     returns the signal mask to be used for waiting the network related
  6063.     messages (4.7, 84).
  6064.  
  6065. 11. domaininit() initializes all configured protocols.  This is left at
  6066.     the end of the initialization, since this requires the other parts of
  6067.     the system to be initialized.
  6068.  
  6069. 12. readnetdb() initializes and reads in the network data base
  6070.     information from ENV:AmInet/netdb (4.12, 92).
  6071.  
  6072. 13. api_show() makes the shared library interface visible on the Exec
  6073.     library list (4.10.2, 91).
  6074.  
  6075.  
  6076.  
  6077. 4.2.2   deinit _all()
  6078.  
  6079. deinit_all() is the reverse of init_all(); it deinitializes required
  6080. modules in reverse order with respect tothe initialization.
  6081.    If the initialization process for a module does not allocate any
  6082. resources, then there is no deinitialization function for that module.
  6083. The deinitialization functions called are (in this order):
  6084.  
  6085.  
  6086.  1. api_hide() removes the library from the Exec librarylist, so no-one
  6087.     can open the library any more (4.10.2, 91).
  6088.  
  6089.  2. sana_deinit() deinitializes the network driver module (4.7, 84).
  6090.  
  6091.  3. api_deinit() deinitializes the API (4.10.2, 91).
  6092.  
  6093.  4. timer_deinit() deinitializes the timer module (5.1,93).
  6094.  
  6095.  5. mbdeinit() frees all memory used by mbufs (4.5, 79).
  6096.  
  6097.  6. log_deinit() deinitializes the logging subsystem (4.8, 89).
  6098.  
  6099.  
  6100.  
  6101. 4.3     The  Main  Module
  6102.  
  6103.  
  6104. The main() function is defined in the file kern/amiga_main.c.  On startup
  6105. it initializes all modules by calling init _all().  After a successful
  6106. initialization it first starts the AmiTCP/IP timeouts by calling
  6107. timer_send().  Then it enters the event loop.
  6108.    AmigaOS function Wait() returns when one of the signals specified in
  6109. the signal mask given as argument is received.   The mask currently
  6110. specifies signals for SANA-II drivers, timeouts and the break signal.
  6111. When some set of these signals is received the Wait() returns and its
  6112. return value, which indicates the received signals, is checked.  The
  6113. functions sana_poll() and timer_poll() are each called in turn if their
  6114. signal was received.  They each return boolean tellingif they would like
  6115. to be called again before waiting again.  The loop in which these
  6116. functions are called is terminated either when no one of the poll
  6117. functions wants to continue or when thebreak signal is received.
  6118.    The pollfunctions do handle only one message at a time, so that any of
  6119. them should not starve.
  6120.  
  6121.  
  6122. 78    Section 4.4                  AmiTCP/IP                   System Manual
  6123.  
  6124.  
  6125.  
  6126.    When thebreak signal is received the AmiTCP/IP terminates if no
  6127. library bases opened by API users are open any more.  On termination all
  6128. reserved resources are freed by callingdeinit _all().
  6129.  
  6130.  
  6131.  
  6132. 4.4     Protocol Entities
  6133.  
  6134.  
  6135. One design goal was to keep the protocolentities intact.  This is
  6136. achieved through implementing all external dependencies of the protocol
  6137. entities.  Fortunately the protocol entities in BSD arehighly
  6138. independent of other UNIX kernel services.   For example, all dynamic
  6139.  
  6140. memory management is done through the memory buffer5  abstraction, which
  6141. means that we only had to provide the mbuf interface and the problem of
  6142. memory management was solved.
  6143.    All protocol entities in a protocol family are defined in terms of a
  6144. protocol switch structure.  This structure is fully defined in the header
  6145. file sys/protosw.h and [Leffler et al 1991b ].  The protocol switch
  6146. structure is defined as follows:
  6147.  
  6148.  
  6149. struct protosw -
  6150.     short   pr_type;             /* socket type used for */
  6151.     struct  domain *pr_domain;  /* domain protocol a member of */
  6152.     short   pr_protocol;         /* protocol number */
  6153.     short   pr_flags;            /* protocol flags */
  6154. /* protocol-protocol hooks */
  6155.      void     (*pr_input)();      /* input to protocol (from below) */
  6156.     int      (*pr_output)();      /* output to protocol (from above)*/
  6157.      void     (*pr_ctlinput)();   /* control input (from below) */
  6158.     int      (*pr_ctloutput)();   /* control output (from above) */
  6159. /* user-protocol hook */
  6160.     int      (*pr_usrreq)();      /* user request hook */
  6161. /* utility hooks */
  6162.      void     (*pr_init)();       /* initialization hook */
  6163.      void     (*pr_fasttimo)();   /* fast timeout (200ms) */
  6164.      void     (*pr_slowtimo)();   /* slow timeout (500ms) */
  6165.      void     (*pr_drain)();      /* flush any excess space possible */
  6166. ";
  6167.  
  6168.  
  6169.    Note thatthe actual prototypes for the function pointers are omitted,
  6170. see the file sys/protosw.h for full definition.
  6171.    When protocol is started the pr_init() is called first to allow the
  6172. protocol to initialize all needed internal structures.  Then the input
  6173. process will call pr_fasttimo() and pr_slowtimo() entries periodically if
  6174.  
  6175. defined6.  The pr_drain() entry asks the protocol tofree all
  6176. non-critical memory buffers in a low-memory situation.
  6177.    Protocolscall each other through the protocol--protocol interface.  To
  6178. pass a packet up in the hierarchy a protocol calls the pr_input()-entry
  6179. of the protocol above it.  pr_output()-entry is called when a protocol
  6180. wishes to pass a packet down in the protocol hierarchy (towards network).
  6181. ________________________________
  6182.    5or mbuf for short
  6183.  
  6184.    6Member function is defined when the value of its address is not NULL.
  6185.  
  6186.  
  6187. System Manual                   AmiTCP/IP                   Section 4.5    79
  6188.  
  6189.  
  6190.  
  6191.    Protocolssend control information to each other through the
  6192. pr_ctlinput() and pr_ctloutput() entries.
  6193.    All requests coming from the API are dispatched through the pr_usrreq()
  6194. entry.
  6195.  
  6196.  
  6197.  
  6198. 4.5     Memory Management
  6199.  
  6200.  
  6201. As stated earlier, the memory managementof the protocol stack is done
  6202. with memory buffers.  An mbuf is a structure containinglittle amount of
  6203. storage (usually 128 bytes).  Some bytes of this storage are used for the
  6204. header, but most of it is used to storeuser data.   These small buffers
  6205. are linked together to get storage for larger data.
  6206.    Mbufs arehighly efficient in a network protocol environment where it
  6207. must be able to attach and strip protocol headers with minimum overhead
  6208. and most importantly, without copying the data as doing so.  When data is
  6209. stored in an mbuf chain, attaching a header is achieved by simply linking
  6210. the mbuf containing the header to the head of the chain.  Removing a
  6211. header is also done simply by removing the first mbuf or by incrementing
  6212. the data pointer inside the mbuf.
  6213.    In general there are two types of mbufs.  Ones with an packet header
  6214. and ones without.  An Mbuf with packet header is used as the first mbuf
  6215. of every packet.  This header contains extra information needed per
  6216. packet.  See the header file sys/mbuf.h for the mbuf header definition.
  6217.    Mbufs canbe chained in two dimensions.  First they may be linked to
  6218. form the storage for the whole message.  Second these messages may be
  6219. linked together so that the boundaries of messages are maintained.  This
  6220. second feature is mainly used by messageoriented protocols such as UDP.
  6221.    To gain efficiency an mbuf may have a reference to external memory page
  6222. (a cluster), where a big message is copied instead of splitting it apart
  6223. to many mbufs.  The main advantage of this feature is avoidance of
  6224. copying the data when sending it with TCP, since the clusters are shared
  6225.  
  6226. between copies7.
  6227.  
  6228.  
  6229.  
  6230. 4.5.1   Mbuf  Functions
  6231.  
  6232.  
  6233. Mbufs are accessed through set of functions which can be grouped as
  6234. follows:
  6235.  
  6236.  
  6237.  
  6238. Maintenance
  6239.  
  6240.  
  6241. int mb_check_conf(void *dp, LONG newvalue)
  6242.  
  6243.     Check configurable variable whose address is dp.  Return TRUE if the
  6244.     newvalue is acceptable value for that variable.  See section 4.11 for
  6245.     information about the configuration.
  6246.  
  6247.  
  6248. BOOL mbinit(void)
  6249. ________________________________
  6250.    7TCP must keep a copy of the sent data for possible retransmissions.
  6251.  
  6252.  
  6253. 80    Section 4.5                  AmiTCP/IP                   System Manual
  6254.  
  6255.  
  6256.  
  6257.     Initialize the whole mbuf-subsystem.  Allocate a chunk of mbufs and
  6258.     clusters (using m_alloc() and m_clalloc).  Must be called before any
  6259.     other mbuf-related function (except that mb_check_conf() can be
  6260.     called anytime).
  6261.  
  6262.  
  6263. void mbdeinit(void)
  6264.  
  6265.     Free all resources used by mbuf subsystem.  Must be called as the
  6266.     last mbuf-related function in the program.
  6267.  
  6268.  
  6269. BOOL m_alloc(int howmany, int canwait)
  6270.  
  6271.     Allocate howmany mbufs and place them on the mbuf free list.  If
  6272.     canwait is true the caller can wait if memory is not readily
  6273.     available.
  6274.  
  6275.  
  6276. BOOL m_clalloc(int ncl, int canwait);
  6277.  
  6278.     Allocate ncl mbuf clusters and place them on the cluster free list.
  6279.  
  6280.  
  6281. struct mbuf *m_retry(int i, int t)
  6282.  
  6283.     Ask protocols to free space when short of memory and re-attempt to
  6284.     allocate an mbuf.
  6285.  
  6286.  
  6287. void m_reclaim(void)
  6288.  
  6289.     Ask protocols to free space when short of memory.
  6290.  
  6291.  
  6292.  
  6293. Allocation and Deallocation
  6294.  
  6295. struct mbuf *m_get(int canwait, int type)
  6296.  
  6297.     Allocate an mbuf of type type.  If no mbufs are available we can wait
  6298.     for them if canwait is M_WAIT. Initialize mbuf to contain internal
  6299.     data.
  6300.  
  6301.  
  6302. void MGET(struct mbuf *m, int canwait, int type)
  6303.  
  6304.     This is an macro form of above.
  6305.  
  6306.  
  6307. struct mbuf *m_gethdr(int canwait, int type)
  6308.  
  6309.     Allocate an mbuf of type type.  If no mbufs are available we can wait
  6310.     for them if canwait is M_WAIT. Initialize mbuf to contain a packet
  6311.     header and internal data.
  6312.  
  6313.  
  6314. void MGETHDR(struct mbuf *m, int canwait, int type)
  6315.  
  6316.     This is a macro form of above.
  6317.  
  6318.  
  6319. struct mbuf *m_getclr(int canwait, int type)
  6320.  
  6321.     Allocate an mbuf of type type.  If no mbufs are available we can wait
  6322.     for them if canwait is M_WAIT. If allocation succeeds the data buffer
  6323.     is zeroed before returning.
  6324.  
  6325.  
  6326. MCLALLOC(struct mcluster *p, int canwait)
  6327.  
  6328.     A macro to allocate an mbuf cluster.  The result is placed in p.
  6329.  
  6330.  
  6331. System Manual                   AmiTCP/IP                   Section 4.5    81
  6332.  
  6333.  
  6334.  
  6335. MCLGET(struct mcluster *p, int canwait)
  6336.  
  6337.     A macro to add a cluster to a normal mbuf.  M_EXT flag of the mbufis
  6338.     set on success.
  6339.  
  6340. struct mbuf *m_free(struct mbuf *m)
  6341.  
  6342.     Free an mbuf.  Next mbuf in the chain is returned, if any.
  6343.  
  6344. void MFREE(struct mbuf *m, struct mbuf *n)
  6345.  
  6346.     This is an macro form of above.  Successor mbuf is returned in n.
  6347.  
  6348. MCLFREE(struct mcluster *p)
  6349.  
  6350.     A macro to free an mbuf cluster.
  6351.  
  6352. void m_freem(struct mbuf *m)
  6353.  
  6354.     Free the whole chain of mbufs starting from m.
  6355.  
  6356.  
  6357.  
  6358. Utility Functions
  6359.  
  6360. struct mbuf *m_copym(struct mbuf *m, intoff0, int len, int canwait)
  6361.  
  6362.     Make a copy of an mbuf chain starting off0 bytes from the beginning
  6363.     of m, continuing for len bytes.  If len is M_COPYALL, copy to endof
  6364.     mbuf.
  6365.  
  6366. void m_copydata(struct mbuf *m, int off,int len, caddr_t cp)
  6367.  
  6368.     Copy data from an mbuf chain starting off bytes from the beginning,
  6369.     continuing for len bytes, into buffer cp.
  6370.  
  6371. struct mbuf *m_prepend(struct mbuf *m, int len, int canwait)
  6372.  
  6373.     Prepend a chain of mbufs (m) with new mbuf with len bytes allocated
  6374.     from the first mbuf aligned on a long word boundary.
  6375.  
  6376. void M_PREPEND(struct mbuf *m, int plen,int canwait)
  6377.  
  6378.     Macro version of above optimized for the most general cases.
  6379.  
  6380. void M_COPY_PKTHDR(struct mbuf *to, struct mbuf *from)
  6381.  
  6382.     Macro for copying an mbuf packet header from from to to.  from must
  6383.     have flag M_PKTHDR set, and to must be empty.
  6384.  
  6385. void M_ALIGN(struct mbuf *m, int len)
  6386.  
  6387.     Macro to set the m data pointer of a newly--allocated mbuf (with
  6388.     m_get()/MGET()) to place an object of the size len at the end of the
  6389.     mbuf, long word aligned.
  6390.  
  6391. void MH_ALIGN(struct mbuf *m, int len)
  6392.  
  6393.     As above, but for mbufs allocated with m_gethdr()/MGETHDR() or
  6394.     initialized by M_COPY_PKTHDR().
  6395.  
  6396. int M_LEADINGSPACE(struct mbuf *m)
  6397.  
  6398.     Compute the amount of space available before the current start of
  6399.     data in an mbuf.
  6400.  
  6401.  
  6402. 82    Section 4.6                  AmiTCP/IP                   System Manual
  6403.  
  6404.  
  6405.  
  6406. int M_TRAILINGSPACE(struct mbuf *m)
  6407.  
  6408.     Compute the amount of space available after the end of data in an
  6409.     mbuf.
  6410.  
  6411.  
  6412. void MCHTYPE(struct mbuf *m, type t)
  6413.  
  6414.     Change mbuf to a new type.
  6415.  
  6416.  
  6417. void m_cat(struct mbuf *m, struct mbuf *n)
  6418.  
  6419.     Concatenate mbuf chain n to m.  Both chains must be of the same type.
  6420.  
  6421.  
  6422. m_adj(struct mbuf *mp, int req_len)
  6423.  
  6424.     Trim req_len bytes from the head of the mbuf chain mp if req_len is
  6425.     positive, else trim -- req_len bytes from the tail of the mbuf chain.
  6426.  
  6427.  
  6428. struct mbuf *m_pullup(struct mbuf *n, int len)
  6429.  
  6430.     Rearrange an mbuf chain so that len bytes from the beginning of the
  6431.     mbuf chain n are contiguous and in the data area of the mbuf so that
  6432.     the data can be used as a structure.
  6433.  
  6434.  
  6435.  
  6436. Utility Macros
  6437.  
  6438. type t mtod(struct mbuf *m, type t)
  6439.  
  6440.     Convert mbuf pointer to a pointer to the start of the data area of
  6441.     the mbuf casted to type t.
  6442.  
  6443.  
  6444. struct mbuf *dtom(type *x)
  6445.  
  6446.     Convert data pointer within an mbuf to mbuf pointer.
  6447.  
  6448.  
  6449.  
  6450. 4.6     Concurrency Control
  6451.  
  6452.  
  6453. The protocol implementation in the BSD net/2 is driven by network and
  6454. timer interrupts and user processes calling the system functions.  As the
  6455. whole protocol stack is moved inside normal AmigaOS process, some
  6456. modifications are in place.
  6457.    The processor priority levels are the main concurrency control tool of
  6458. the BSD kernel.  The levels defined are SPL0 (user level), SPLSOFTCLOCK,
  6459. SPLNET and SPLIMP (the most privileged level).   Execution at a higher
  6460. level disables the execution at all lower levels.   InAmiTCP/IP the
  6461. concurrency control is implemented either with semaphores (when
  6462. debugging) or with prevention of the task switches (Forbid()/Permit()),
  6463. see section 5.3.1 on page 96 for the implementation notes.
  6464.    The protocol input and timeouts are driven by a single process that
  6465. manages the whole protocol stack.  The process sends appropriate IO
  6466. requests to the timer device and the SANA-II device drivers in question.
  6467. Actions are then taken as response to the returned requests.  Before any
  6468. protocol routines are called the priority level is raised either to
  6469. SPLSOFTCLOCK or SPLNET. After the function returns the priority level is
  6470. lowered back to SPL0 and the request issent back to the device driver.
  6471.  
  6472.  
  6473. System Manual                   AmiTCP/IP                   Section 4.7    83
  6474.  
  6475.  
  6476.  
  6477.    On the API side the concurrent execution of system calls is mostly
  6478. prohibited, because in UNIX the system calls are atomic in the sense that
  6479. there is never more than one system callin execution.  In AmigaOS the
  6480. shared library functions must be re-entrant so the protection must be
  6481. provided by the library functions themselves.
  6482.    The priority at which the main process runs must be above the default
  6483. value of 0 to provide enough time to process the networking protocols.
  6484. On the other side there is no sense to drive the main process at greater
  6485. priority than the SANA-II device drivers.
  6486.  
  6487.  
  6488.  
  6489. 4.7     Network  Device  Drivers
  6490.  
  6491.  
  6492. AmiTCP/IP uses standard SANA-II driversas its external network device
  6493. drivers.  A little glue is needed to attach a SANA-II driver into BSD
  6494. net/2 code.
  6495.  
  6496.  
  6497.  
  6498. Network Interface
  6499.  
  6500. The BSD net/2 networking code provides aclean interface to the network
  6501. device drivers.  The network interface provides a consistent interface
  6502. for all protocols that may be present inthe BSD Unix kernel.  Each
  6503. hardware device is associated with an unique network interface which may
  6504. be used by one or more protocol families.
  6505.    The network interface is flexible enough to attach different SANA-II
  6506. network device drivers into the AmiTCP/IP networking system.  Common
  6507. part of all network interfaces is described in [Leffler et al 1991b  ]:
  6508.  
  6509.  
  6510. struct ifnet -
  6511.          char    *if_name;               /* name, e.g. "en" or "lo" */
  6512.          short   if_unit;                /* sub-unit for lower level driver */
  6513.          short   if_mtu;                 /* maximum transmission unit */
  6514.          short   if_flags;               /* up/down, broadcast, etc. */
  6515.          short   if_timer;               /* time 'til if_watchdog called */
  6516.          int     if_metric;              /* routing metric (external only) */
  6517.          struct  ifaddr *if_addrlist;    /* linked list of addresses per if */
  6518.          struct  ifqueue -
  6519.                  struct  mbuf *ifq_head;
  6520.                  struct  mbuf *ifq_tail;
  6521.                  int      ifq_len;
  6522.                  int      ifq_maxlen;
  6523.                  int      ifq_drops;
  6524.          " if_snd;                       /* output queue */
  6525. /* procedure handles */
  6526.          int     (*if_init)();           /*init routine */
  6527.          int     (*if_output)();         /* output routine (enqueue) */
  6528.          int     (*if_start)();         /* initiate output routine */
  6529.          int     (*if_done)();           /*output complete routine */
  6530.          int     (*if_ioctl)();         /* ioctl routine */
  6531.          int     (*if_reset)();         /* bus reset routine */
  6532.          int     (*if_watchdog)();      /* timer routine */
  6533. /* generic interface statistics */
  6534.          int     if_ipackets;            /* packetsreceived on interface */
  6535.  
  6536.  
  6537. 84    Section 4.7                  AmiTCP/IP                   System Manual
  6538.  
  6539.  
  6540.  
  6541.          int     if_ierrors;             /* input errors on interface */
  6542.          int     if_opackets;            /* packetssent on interface */
  6543.          int     if_oerrors;             /* output errorson interface */
  6544.          int     if_collisions;         /* collisions on csma interfaces */
  6545. /* end statistics */
  6546.          struct  ifnet *if_next;
  6547. ";
  6548.  
  6549.  
  6550.    Network interface for SANA-II devices are handled in the module
  6551. net/if_sana.c.  This is the only module aware of SANA-II devices inside
  6552. the AmiTCP/IP network process.  It hides most SANA-II specific details
  6553. from the rest of the code.
  6554.  
  6555.  
  6556.  
  6557. Module Initialization
  6558.  
  6559. ULONG sana_init(void)
  6560.  
  6561.     This initialization routine is called at startup time before any
  6562.     interfaces have been added to system.  It creates the common message
  6563.     port used for all SANA-II network interfaces.  It also attaches the
  6564.     loopback device into system.  It returns the signal mask of the
  6565.     message port, if its creation was successful.
  6566.  
  6567. void sana_deinit(void)
  6568.  
  6569.     This routine frees all resources allocated by the SANA-II interface
  6570.     module.  It aborts all pending IO requests, frees them, closes
  6571.     network device drivers and frees the corresponding network
  6572.     interfaces.  Finally it deletes the message port.
  6573.  
  6574.  
  6575.  
  6576. 4.7.1   SANA-II Soft Network Interface
  6577.  
  6578. A message passing system based on the normal Exec IO requests is used to
  6579. transfer packets between the AmiTCP/IP and SANA-II devices.  The IO can
  6580. be either synchronous or asynchronous.  The SANA-II interface module has
  6581. a message port, which receives all fulfilled or aborted asynchronous IO
  6582. messages.  A dispatch method (currently a dispatch function pointer) have
  6583. been added to all asynchronously sent IOrequests.   Dispatching function
  6584. handles the received message in an appropriate way.
  6585.    A messagemay contain received packet, some buffers allocated for the
  6586. sent message or an event mask.  Dispatcher functions feed the received
  6587. data to the protocol input queues.  If needed, the protocol input
  6588. routines are run.  Dispatchers also free the memory allocated for the
  6589. sent packets, or relays events to the higher level protocols.
  6590.    Because the interface for the SANA-II device driver must handle many
  6591. different protocols and network adapters, it has some private data hidden
  6592. from the rest of the system.  The struct sana_softc network interface is
  6593. defined in file net/if_sana.h:
  6594.  
  6595. /*
  6596.  * SANA-II Interface descriptor
  6597.  *      NOTE: most of the code outside will believe this to be simply
  6598.  *      a "struct ifnet". The other information is, on the other hand,
  6599.  *      our own business.
  6600.  
  6601.  
  6602. System Manual                   AmiTCP/IP                   Section 4.7    85
  6603.  
  6604.  
  6605.  
  6606.  */
  6607. struct sana_softc -
  6608.   struct ifnet    ss_if;               /* network-visible interface */
  6609.   struct in_addr  ss_ipaddr;          /* copy of ip address */
  6610.   ULONG            ss_hwtype;           /* wiretype */
  6611.   UBYTE            ss_hwaddr[MAXADDRSANA]; /* Generalhardware address */
  6612.   struct Device  *ss_dev;              /* pointer todevice */
  6613.   struct Unit    *ss_unit;             /* pointer to unit */
  6614.   VOID            *ss_bufmgnt;         /* magic cookie for buffer mngement */
  6615.   UWORD            ss_reqno;            /* # of requests to allocate */
  6616.   struct IOIPReq *ss_reqs;             /* allocated requests*/
  6617.   struct MinList  ss_freereq;         /* free requests */
  6618. #if     INET
  6619.   struct -
  6620.     UWORD reqno;               /* for listening ip packets */
  6621.     UWORD sent;
  6622.     ULONG type;
  6623.   " ss_ip;
  6624.   struct -                        /* for ARP */
  6625.     UWORD reqno;
  6626.     UWORD sent;
  6627.     ULONG type;                  /* ARP packet type */
  6628.     ULONG hrd;                    /*ARP header type */
  6629.     struct arptable *table;     /* ARP/IP table */
  6630.   " ss_arp;
  6631. #endif  /* INET */
  6632.   UWORD            ss_rawreqno;        /* for raw packets */
  6633.   UWORD            ss_rawsent;
  6634.   struct sana_softc *ss_next;
  6635.   char             ss_name[IFNAMSIZ];  /* namelives here */
  6636. ";
  6637.  
  6638.    There isan external interface to this structure via SIOCSSANATAGS and
  6639. SIOCGSANATAGS ioctls.
  6640.  
  6641.  
  6642. struct ifnet *iface_find(char *name)
  6643.  
  6644.     This function initializes a network interface for given interface.
  6645.     It is called on a non-existent interface from ifunit().  It tries to
  6646.     open the appropriate SANA-II device driver, and if successful it
  6647.     initializes a descriptor and calls if_attach() with it.
  6648.  
  6649.     Its argument is the device driver name concatenated with a slash and
  6650.     unit number.  This name is used by AmiTCP/IP to open appropriate
  6651.     unit of the SANA-II driver.
  6652.  
  6653.     The initialization routine provides the specified SANA-II network
  6654.  
  6655.     device unit with the CopyToBuf() and CopyFromBuf() function tags8.
  6656.     Those tags are used to copy data to and from the internal buffers of
  6657.     the network device.  The taglist given to the device driver is
  6658.     defined in file net/sana2copybuff.c.
  6659.  
  6660.     After successful open iface_find() initializes the appropriate
  6661.     members of the new sana_softc structure.  It stores the device and
  6662.     unit pointers, magic cookie for buffer management, hardware type, MTU
  6663. ________________________________
  6664.    8For discussion for these functions, see [SANA-II 1992 add  ]
  6665.  
  6666.  
  6667. 86    Section 4.7                  AmiTCP/IP                   System Manual
  6668.  
  6669.  
  6670.  
  6671.     and address length.  It also searches for the hardware type specific
  6672.     taglist, and sets the rest of interface parameters according the
  6673.     taglist.
  6674.  
  6675.     Next the interface initialization routine attaches the new network
  6676.     interface into ifnet list with if_attach().  Then it initializes
  6677.     interface with if_init().
  6678.  
  6679.  
  6680.  
  6681. Interface Routines
  6682.  
  6683. BOOL sana_poll(void)
  6684.  
  6685.     The AmiTCP/IP processes received messages by calling this function.
  6686.     It effectively hides the actual implementation from the rest of the
  6687.     system.  This routine is called when AmiTCP/IP receives the signal
  6688.     allocated by sana_init(), and it returns TRUE, if itshould be called
  6689.     again before Wait().
  6690.  
  6691.     sana_poll() retrieves messages from the message port, dispatches them
  6692.     and then runs the input queues.
  6693.  
  6694. int sana_output(struct ifnet *ifp, struct mbuf *m0,
  6695.                 struct sockaddr *dst, struct rtentry *rt)
  6696.  
  6697.     This function is used as the if_output() method.  It tries to get a
  6698.     free IO request from the ss_freereq list.  If no free request is
  6699.     available it drops the packet.  It attaches the packet m0 to request,
  6700.     sets dispatching function to free_written_packet() and sends the
  6701.     request to the device driver.
  6702.  
  6703.     The raw packets to the SANA-II interface use the following variation
  6704.     of socket address.  The addressing family of the raw packets must be
  6705.     AF_UNSPEC. Currently only the ARP uses the raw SANA-II packets.
  6706.  
  6707.  
  6708.     /*
  6709.      * A socket address for a generic SANA-II host
  6710.      */
  6711.     struct sockaddr_sana2 -
  6712.        u_char ss2_len;
  6713.        u_char ss2_family;
  6714.        u_long ss2_type;
  6715.        u_char ss2_host[MAXADDRSANA];
  6716.     ";
  6717.  
  6718.  
  6719. void sana_ioctl(struct ifnet *ifp, int cmd, caddr_t data)
  6720.  
  6721.     This function is used as the if_ioctl() method.  SANA-II devices and
  6722.     their respective network interfaces are configured via raw sockets by
  6723.     the IoctlSocket() requests.  When the sana_ioctl() gets the
  6724.     SIOCSIFADDR request, it changes the IP address of the interface.  The
  6725.     SIOCGIFFLAGS ioctl is used to set the parameter flags of the
  6726.  
  6727.     interface9.
  6728.  
  6729.     Special SANA-II configuration is done with SIOCSSANATAGS ioctl.  It
  6730.     passes a tag list to the parse_sana_param_tags() function.
  6731. ________________________________
  6732.    9See file sys/ioctl.h for full listof all ioctls
  6733.  
  6734.  
  6735. System Manual                   AmiTCP/IP                   Section 4.7    87
  6736.  
  6737.  
  6738.  
  6739. void if_down(struct ifnet *ifp)
  6740.  
  6741.     This function pulls into if_ioctl() from net/if.h.  if_down() marks
  6742.     the interface down and informs all affected network protocols about
  6743.     the matter.  If the interface handles SANA-II device, it calls
  6744.     sana_down(), which handles the dirty work to put theinterface down.
  6745.  
  6746. static void sana_run(struct sana_softc *ssc, int n, struct ifaddr *ifa)
  6747.  
  6748.     sana_run() configures the SANA-II interface and allocates the IO
  6749.     requests to use with the SANA-II device driver.  Because the SANA-II
  6750.     device can be configured only once (see S2_CONFIGINTERFACE in
  6751.     [SANA-II 1992 add  ]) the initialization routine does not configure it.
  6752.     Among other things the hardware address of the network adapter is set
  6753.     in configuration process.  This function is called by the SIOGSIFADDR
  6754.     ioctl, which also sets the protocol address of the interface.
  6755.  
  6756. static void sana_up(struct sana_softc *ssc)
  6757.  
  6758.     sana_up() marks interface up and enables the interface to listen the
  6759.     packets from the network.  It sends read request with an appropriate
  6760.     packet type number and dispatch function to the device.
  6761.  
  6762. static BOOL sana_down(struct sana_softc*ssc)
  6763.  
  6764.     sana_down() aborts all pending requests sent to a SANA-II device
  6765.     driver.
  6766.  
  6767. static void sana_ip_read(struct sana_softc *ssc,
  6768.     struct IOIPReq *req) and
  6769.  
  6770. static void sana_arp_read(struct sana_softc *ssc,
  6771.     struct IOIPReq *req)
  6772.  
  6773.     These dispatch functions are used to feed data from a network device
  6774.     to the protocol input queues.  The network interface has not the
  6775.     input routines as members.  Dispatching functions allocate mbufs for
  6776.     the next packet and send IO requests again to the network device.
  6777.  
  6778.  
  6779.  
  6780. Statistics
  6781.  
  6782. BSD Network interface contains a lot ofexcessive statistical data.  Most
  6783. of it is made redundant by the statistics gathered by the SANA-II driver.
  6784. Because network statistics are not retrieved by looking at /dev/kmem,
  6785. there is no need to gather BSD compatible statistics.  A public ARexx
  6786. port, named AMITCP, is set up for statistics retrieval and we can use
  6787. appropriate SANA-II commands to get needed data when asked.
  6788.  
  6789.  
  6790.  
  6791. 4.7.2   ARP
  6792.  
  6793. The requirements for the ARP implementation for a SANA-II interface
  6794. differ radically from the original implementation BSD. The original code
  6795. was written exclusively for the Ethernet, which has a global addressing
  6796. scheme and a fixed address length.
  6797.    The SANA-II ARP (in the module net/sana2arp.c) holds a separate address
  6798. mapping cache for each interface.  The number of entries in the cache may
  6799.  
  6800.  
  6801. 88    Section 4.8                  AmiTCP/IP                   System Manual
  6802.  
  6803.  
  6804.  
  6805. be configured at the run time.  The hardware address length varies from
  6806. one interface to another.  The mapping caches are hashtables with linked
  6807. lists, so there is no limitations in thebucket size.  ARP Table locking
  6808. is done with a signal semaphore insteadof spln() functions.
  6809.    The ARP table is externally accessed only by IoctlSocket() calls.  With
  6810. the new SIOCGARPT ioctl the whole ARP cache may be read at once.  There
  6811. is no need to awkwardly read /dev/kmem.
  6812.  
  6813.  
  6814.  
  6815. 4.8     Logging
  6816.  
  6817.  
  6818. As everything is not predictable, programs like to inform the user about
  6819. certain situations to help the user and/or maintainer to get programs
  6820. work better.  This is the motivation for log() and panic() functions.
  6821. The fact that the file I/O routines can't be called from interrupts must
  6822. be taken into account, since a program may want to inform the user even
  6823. while executing at an interrupt level.
  6824.    Among thevery few functions of the AmigaOS which are callable from
  6825. interrupts are GetMsg() and PutMsg().  These are used to implement the
  6826. logging subsystem.
  6827.    When AmiTCP/IP has something to tell to the user, it first checks if
  6828. there is any free messages available.  There is only alimited number of
  6829. these messages to use, since they are preallocated during
  6830.  
  6831. initialization10.  If there is no message available, a counter indicating
  6832. that the message could not be deliveredis incremented.  If a free
  6833. message is available, the text given bycaller is printed into the buffer
  6834. of the message.  Then the message is sent to the private port of the
  6835. NETTRACE task.
  6836.    The NETTRACE task is created early in the initialization of the
  6837. AmiTCP/IP. This task waits for incomingmessages and when one arrives,
  6838. it prints the message to the log windowand/or log file.  Then message is
  6839. freed by sending it back to AmiTCP/IP for reuse.   If loss of log
  6840. messages is detected, log() is called totell that to the user.
  6841.    The functions are defined as follows:
  6842.  
  6843.  
  6844. int log(unsigned long level, const char*fmt, ...)
  6845.  
  6846.     This logs a message with format specified in exec.library/RawDoFmt(),
  6847.     similar to the printf().  It is preceded with ``<N>'' where N is a
  6848.     level as defined in file sys/syslog.h.
  6849.  
  6850. void panic(const char *fmt, ...)
  6851.  
  6852.     When this function is called, we are in BIG trouble.  If task, which
  6853.     called this, is not AmiTCP/IP, we just halt this task and send a
  6854.     message to AmiTCP/IP to halt immediately and free all resources.
  6855.     Format is as in exec.library/RawDoFmt().
  6856.  
  6857.     If AmiTCP/IP runs into a panic() it first patches all API functions
  6858.     to return an error code to the caller.  Then, if the panic() was not
  6859.     in the context of the AmiTCP/IP it signals the AmiTCP/IP and halts.
  6860.     As the AmiTCP/IP receives the signal, it send a message to the log
  6861. ________________________________
  6862.   10This is because memory cannotbe allocated from interrupt code.
  6863.  
  6864.  
  6865. System Manual                   AmiTCP/IP                   Section 4.9    89
  6866.  
  6867.  
  6868.  
  6869.     and signals all application programs waiting for network to take
  6870.     attention.  As this is done, it opens an User Requester to inform the
  6871.     user.  After the user responds, AmiTCP/IP waits for all library
  6872.     openers to close libraries and finally unloads itself from the
  6873.     memory.
  6874.  
  6875. int printf(const char *fmt, ...)
  6876.  
  6877.     Like the normal C--library printf (with format of
  6878.     exec.library/RawDoFmt()) except that the printing is done using the
  6879.     logging mechanism.
  6880.  
  6881. int sprintf(char *buf, const char *fmt,...)
  6882.  
  6883.     As in a normal C--library.  Format is as in exec.library/RawDoFmt().
  6884.  
  6885.  
  6886.    All functions (except panic()) return number of printed (or logged)
  6887. characters.
  6888.  
  6889.  
  6890.  
  6891. Initialization Routines
  6892.  
  6893. BOOL log_init(void)
  6894.  
  6895.     This function initializes NETTRACE subsystem by opening
  6896.     intuition.library for opening UserRequest in the case of panic().
  6897.     The the log messages are initialized to use by preallocating memory
  6898.     for them.
  6899.  
  6900.     Then NETTRACE is started and AmiTCP/IP waits for a signal from it.
  6901.     If NETTRACE success in it's initialization, then it sends a message
  6902.     back, which is then replied.  If initialization fails, a variable is
  6903.     set to specific value and CTRL-F is sent to the AmiTCP/IP. If all
  6904.     this succeeds, the log messages are initialized and sent to
  6905.     logReplyPort which works as a queue for the free messages.
  6906.  
  6907. void log_deinit(void)
  6908.  
  6909.     This works as reverse to initialization process.  If NETTRACE is
  6910.     still running, a message is sent to it telling it to terminate.  Then
  6911.     AmiTCP/IP waits until the message is replied.  Then the memory
  6912.     reserved by the messages can be freed.  Finally the intuition.library
  6913.     is closed.
  6914.  
  6915.  
  6916.  
  6917. 4.9     ARexx Interface
  6918.  
  6919.  
  6920. The ARexx port of the AmiTCP/IP is maintained by the NETTRACE task.  The
  6921. messages are parsed with parseline() (defined in kern/amiga_config.c).
  6922.  
  6923.  
  6924.  
  6925. Initialization Routines
  6926.  
  6927. ULONG rexx_init(void)
  6928.  
  6929.     This initialization routine is called at the startup time of the
  6930.     NETTRACE process.  It opens the utility.library and the
  6931.     rexxsyslib.library to be used by the ARexx code and creates a public
  6932.  
  6933.  
  6934. 90    Section 4.10                 AmiTCP/IP                  System Manual
  6935.  
  6936.  
  6937.  
  6938.     ARexx message port.  The signal mask of the ARexx port is returned
  6939.     upon a successful initialization.
  6940.  
  6941.  
  6942. void rexx_deinit(void)
  6943.  
  6944.     Free all resources allocated by the ARexx interface module.  First
  6945.     the ARexx port is removed from the system's list of message ports so
  6946.     that no-one is able find the port any more to send new messages.
  6947.     Then all pending messages are returned with error code set.  Finally
  6948.     the ARexx port is deleted and libraries opened by rexx_init() are
  6949.     closed.
  6950.  
  6951.  
  6952.  
  6953. Reply Routine
  6954.  
  6955. BOOL rexx_poll(void)
  6956.  
  6957.     Checks if any ARexx messages has arrived and handles them one at a
  6958.     time.  The parseline() function is used to parse and execute the
  6959.     given command.  Returns TRUE if there might still be messages to
  6960.     handle, otherwise the return value is FALSE.
  6961.  
  6962.  
  6963.  
  6964. 4.10     Application  Interface  Concepts
  6965.  
  6966.  
  6967. 4.10.1   SocketBase -- an Extension of the Task Structure
  6968.  
  6969. In Unix systems, where the network codeis integrated into the kernel, a
  6970. process structure holds fields for per-process information of network
  6971. related data.  In AmiTCP/IP, where socket API is implemented as a shared
  6972. library, each opener gets a newly created library base that holds data
  6973. used by the AmiTCP/IP system.  Each library base function makes sure
  6974. that the caller is from the right Amigatask and refuses to operate if
  6975. wrong task is attempting to use it (seesection 5.5 on page 100 for
  6976. detailed information).
  6977.  
  6978.  
  6979.  
  6980. 4.10.2   The System Call Semaphore and Task Priorities
  6981.  
  6982. Currently, when program enters to some of socket library functions, it
  6983. attempts to get semaphore to hold othercallers executing library code
  6984. simultaneously.  This is done so, since in Unix system,where this code
  6985. originally runs, doesn't pre-empt process that is executing system call.
  6986. In BSDSS, where ``Unix system calls'' run in user mode, system call
  6987. emulation glue uses a mutex to prevent simultaneous use of that part of
  6988. the server code.  Although spl functions are used in NET/2 code to
  6989. prevent simultaneous access of criticalsections, there may still be some
  6990. sections that leave out protection if system call semaphore is removed.
  6991. Unnecessary system call semaphore usageis going to be removed in later
  6992. releases.  Hopefully it, and the overhead it generates,becomes obsolete.
  6993.    The priority of the application process is raised to the same with the
  6994. AmiTCP/IP, while the application executes AmiTCP/IP code.  This is to
  6995. prevent situations where a process witha low priority gets blocked for a
  6996. long time while holding e.g.  the system call semaphore, since otherwise
  6997.  
  6998.  
  6999. System Manual                  AmiTCP/IP                 Section 4.11    91
  7000.  
  7001.  
  7002.  
  7003. all networking programs would be blockedwith it.   Thisapplies to all
  7004. semaphores used internally by the AmiTCP/IP, not just the system call
  7005. semaphore.
  7006.  
  7007.  
  7008.  
  7009. Initialization Routines
  7010.  
  7011. Making application interface visible andoperative contains a few steps:
  7012. call to api_init() creates the master socket library base and initializes
  7013. semaphores and lists API needs.  Library base is not inExec library base
  7014. list yet.  Routine api_show() checks first if bsdsocket.library is
  7015. already in Exec list and if not, calls Exec AddLibrary() to make it
  7016. visible.
  7017.    AmiTCP/IPcan remove socket library from the Exec list at any time,
  7018. i.e.  make it not visible, by calling api _hide().  No new socket bases
  7019. can be opened after this call.  Socket bases opened before api _hide()
  7020. operate normally.  If AmiTCP/IP calls api_show() again, new libraries can
  7021. be opened.
  7022.    api_setfunctions() takes all socket library bases out of operation.  It
  7023. sets all function vectors in every socket base to return an error.  This
  7024. function is called if AmiTCP/IP panic()ed and all libraries are expected
  7025. to be closed.
  7026.    When application interface is to be removed from system, api_deinit()
  7027. is called.  It waits for all opened libraries to closeand then calls
  7028. expunge function to deallocate the master socket base from the memory.
  7029.  
  7030.  
  7031.  
  7032. 4.11     Configuration  Variables
  7033.  
  7034.  
  7035. The configuration variable definitions are stored into a structure named
  7036. cfg_variable.  It is defined in kern/amiga_netdb.h as follows:
  7037.  
  7038.  
  7039. /* Variable types */
  7040. /* Note: Query calls value, Set calls notify functions */
  7041. enum var_type
  7042. -
  7043.  VAR_FUNC = 1,           /* value is function pointer */
  7044.  VAR_LONG,               /* value is pointer to LONG */
  7045.  VAR_STRP,               /* value is pointer to string */
  7046.  VAR_FLAG,               /* LONG value is set once */
  7047.  VAR_INET,               /* struct sockaddr_in */
  7048.  VAR_ENUM                /* value is pointer to long, whose value is set
  7049.                              according to a enumeration string in notify*/
  7050. ";
  7051.  
  7052.  
  7053. typedef LONG
  7054.   (*var_f)(struct CSource *args, UBYTE **errstrp, struct CSource *res);
  7055. typedef int (*notify_f)(void *pt, LONG new);
  7056.  
  7057.  
  7058. /* Configureable variable structure */
  7059. struct cfg_variable -
  7060.   enum var_type type;            /* type of value */
  7061.  
  7062.  
  7063. 92    Section 4.12                 AmiTCP/IP                  System Manual
  7064.  
  7065.  
  7066.  
  7067.   WORD  flags;                   /* see below */
  7068.   const UBYTE *index;            /* optional index keyword list */
  7069.   void  *value;                  /* pointer to value... */
  7070.   notify_f notify;               /* notification function */
  7071. ";
  7072.  
  7073.  
  7074. #define boolean_enum (notify_f)"NO=FALSE=OFF=0,YES=TRUE=ON=1"
  7075.  
  7076.  
  7077. /* Variable flags */
  7078. #define VF_TABLE    (1<<0) /* with an index... */
  7079. #define VF_READ     (1<<1) /* readable */
  7080. #define VF_WRITE    (1<<2) /* writeable */
  7081. #define VF_CONF     (1<<3) /* writeable only during configuration */
  7082. #define VF_RW       (VF_WRITE_VF_READ)
  7083. #define VF_RCONF    (VF_CONF_VF_READ)
  7084. #define VF_FREE     (1<<8) /* free when replaced? */
  7085.  
  7086.  
  7087.    The configuration file (by default AmiTCP:db/AmiTCP.config) is read
  7088. with the function readconfig().  This function also parses the command
  7089. line arguments.
  7090.  
  7091.  
  7092.  
  7093. 4.12     Network  Database
  7094.  
  7095.  
  7096. The network database is initialized by the init _netdb() function.  This
  7097. function allocates the NetDataBase structure and parses the file
  7098. AmiTCP:db/netdb.  The NetDataBase structure is definedas follows:
  7099.  
  7100.  
  7101. struct NetDataBase -
  7102.   struct SignalSemaphore ndb_Lock;
  7103.   struct MinList          ndb_Hosts;
  7104.   struct MinList          ndb_Networks;
  7105.   struct MinList          ndb_Services;
  7106.   struct MinList          ndb_Protocols;
  7107.   struct MinList          ndb_NameServers;
  7108.   struct MinList          ndb_Domains;
  7109. ";
  7110.  
  7111.  
  7112.    This structure contains a lock and lists for the different network
  7113. database entries.  The lock semaphore is obtained in the shared mode for
  7114. reading, and in the exclusive mode for writing.   See section 2.5.1 for
  7115. the information about the different entries.
  7116.  
  7117.  
  7118.  
  7119.  
  7120.  
  7121. Chapter 5
  7122.  
  7123.  
  7124.  
  7125. Implementation Notes
  7126.  
  7127.  
  7128.  
  7129. This chapter describes some points of the implementation of the
  7130. AmiTCP/IP. The code that is not changedfrom the BSD net/2 -release is
  7131. not reviewed.  [Leffler et al 1989 ] describes the design and
  7132. implementation of the BSD Unix, including the networking system.
  7133. [Leffler et al 1991b ] is also very helpful.
  7134.    Most of the knowledge gathered during this project is gained by reading
  7135. the source code itself.  This chapter does not try to make that totally
  7136. unnecessary.
  7137.  
  7138.  
  7139.  
  7140. 5.1     Time outs
  7141.  
  7142.  
  7143. The Unix timeout() function implements the time out needs of the Unix
  7144. kernel.  When kernel code calls timeout(), the functiongiven as argument
  7145. will be called after the specified timeout has elapsed.  In AmigaOS time
  7146. outs are provided by the timer device.  AmiTCP/IP sendstime out
  7147. requests to the device and gets them back when the time specified has
  7148. elapsed.
  7149.    The functions called by the time out service are:
  7150.  
  7151.  
  7152. if_slowtimo()
  7153.  
  7154.     This is the time out function of the network interfaces and is
  7155.     defined in net/if.c.
  7156.  
  7157.  
  7158. arptimer()
  7159.  
  7160.     Handles the time outs of ARP protocol (net/sana2arp.c).
  7161.  
  7162.  
  7163. pfslowtimo()
  7164.  
  7165.     This is the main slow time out function for all protocols.  It calls
  7166.     the pr_slowtimo() function of each configured protocol.   The interval
  7167.     of this timer is 500 ms (kern/uipc_domain.c).
  7168.  
  7169.  
  7170. pffasttimo()
  7171.  
  7172.     Is the corresponding function for fast (200 ms) time outs.
  7173.  
  7174.  
  7175.  
  7176.                                       93
  7177.  
  7178.  
  7179. 94    Section 5.1                  AmiTCP/IP                   System Manual
  7180.  
  7181.  
  7182.  
  7183.    The request structure used by AmiTCP/IP has few fields in addition to
  7184.  
  7185. the normal struct timerequest1.  The structure is defined in
  7186. kern/amiga_time.h as follows:
  7187.  
  7188. struct timeoutRequest -
  7189.   struct timerequest timeout_request;   /* timer.device sees only this */
  7190.   struct timeval     timeout_timeval;   /* timeout interval */
  7191.   TimerCallback_t    timeout_function;  /* timeout function to be called */
  7192. ";
  7193.  
  7194.  
  7195.    In this implementation the time out functions themselves do not call
  7196. any time out services, but the functionsare called by timer_poll(),
  7197. which is called by main() when there might be a message to handle (e.g.
  7198. when the timer signal is received).  timer_poll() checks the reply port
  7199. to see if there really is a message to handle.   Afterthe time out
  7200. function is serviced timer_poll() sends the request back to the timer
  7201. device and returns.
  7202.    Time outservice is implemented by files kern/amiga_time.c and
  7203. kern/amiga_time.h.  The functions defined are:
  7204.  
  7205.  
  7206. ULONG timer_init(void)
  7207.  
  7208.     Initializes the time out subsystem by allocating the IO requests and
  7209.     opening the timer device.  Note that AmiTCP/IP uses functions that
  7210.     are new to version 36 of the timer device, so the code refuses to
  7211.     success with Kickstart 1.3 (or lower).
  7212.  
  7213.     Returns the signal mask to wait for if successful.
  7214.  
  7215. void timer_deinit(void)
  7216.  
  7217.     Frees all resources used by time out subsystem.
  7218.  
  7219. void timer_send(void)
  7220.  
  7221.     Sends time out requests allocated by timer_init() tothe timer
  7222.     device.
  7223.  
  7224. struct timeoutRequest *createTimeoutRequest(TimerCallback_t fun,
  7225.     ULONG seconds, ULONG micros)
  7226.  
  7227.     Creates a new time out request.  This can be called only after
  7228.     successful timer_init().
  7229.  
  7230. void deleteTimeoutRequest(struct timeoutRequest *tr)
  7231.  
  7232.     Deletes requests created by createTimeoutRequest().
  7233.  
  7234. BOOL timer_poll(VOID)
  7235.  
  7236.     Checks if there are any timer requests in the reply port and if there
  7237.     is handles them by calling the handleTimeoutRequest().  Then it sends
  7238.     the request back to the timer device.
  7239.  
  7240. void handleTimeoutRequest(struct timeoutRequest *tr)
  7241.  
  7242.     Inline function which simply calls the function specified in the time
  7243.     out request.
  7244. ________________________________
  7245.    1See standard Amiga include file devices/timer.h
  7246.  
  7247.  
  7248. System Manual                   AmiTCP/IP                   Section 5.2    95
  7249.  
  7250.  
  7251.  
  7252. void sendTimeoutRequest(struct timeoutRequest *tr)
  7253.  
  7254.     Inline function which sends the request to the timer device.
  7255.  
  7256.  
  7257.    See the files kern/amiga_main.c and kern/amiga_time.c for example of
  7258. the usage.
  7259.  
  7260.  
  7261.  
  7262. 5.2     Memory Management
  7263.  
  7264.  
  7265. 5.2.1   Mbufs
  7266.  
  7267. Mbufs are ported just as they are.  Memory is allocatedin small chunks
  7268. for both mbufs and clusters.  The size of the cluster and the number of
  7269. mbufs to allocate in one chunk are configurable variables, see section
  7270. 2.4 for summary of the configurable variables in general.
  7271.    Note thatsince data must be copied at the SANA-II interface there is
  7272. no need to use trailer protocols (whosemain gain is avoidance of that
  7273.  
  7274. copy) and so the mbuf clusters need notbegin at page boundaries2.   This
  7275. fact lead to the implementation of the clusters where the size of the
  7276. cluster may be arbitrary (now user configurable) and the reference count
  7277. of the cluster is stored in a little header before the actual data.
  7278.    One noteon allocating memory for the mbufs:  Since the mbuf must be
  7279. perfectly aligned (i.e.  128 byte mbuf must be 128--aligned), we need to
  7280. allocate one extra mbuf to be able to align the mbufs in arbitrary memory
  7281. chunk returned by Exec AllocMem().
  7282.    The 'canwait' argument of the mbuf functions is ignored by now, more
  7283. memory will be allocated if limit of maximum memory usage is not hit.
  7284. This is all right as long as the mbuf allocation functions are not called
  7285. from interrupts.  The only functions in the AmiTCP/IP which may get
  7286. called from the interrupt code are the SANA-II callback functions
  7287. m_copy_from_mbuf() and m_copy_to_mbuf()defined in file
  7288. net/sana2copybuff.c.
  7289.    The function descriptions for the mbufs are on section 4.5.  See files
  7290. sys/mbuf.h and kern/uipc_mbuf.c for the actual implementation.
  7291.  
  7292.  
  7293.  
  7294. 5.2.2   malloc() & free()
  7295.  
  7296. Do not call the malloc() and free() functions directly!  Since AmiTCP/IP
  7297. is multi--threaded program these functions are not safe, since they use
  7298. static data.  File sys/malloc.h defines two inline functions to be used
  7299. instead.  They are defined as follows:
  7300.  
  7301.  
  7302. static inline void * bsd_malloc(unsignedlong size, int type, int flags)
  7303.  
  7304.     This function calls malloc() to allocate memory of size size and type
  7305.     type.  The types are defined in sys/malloc.h and are used for
  7306.     bookkeeping purposes.  The flags may have either value M_WAITOK or
  7307.     M_NOWAIT. The flags are not used by this implementation, however, but
  7308.     are defined for portability.
  7309. ________________________________
  7310.    2Well, there is no virtual memory in Amiga either.
  7311.  
  7312.  
  7313. 96    Section 5.3                  AmiTCP/IP                   System Manual
  7314.  
  7315.  
  7316.  
  7317. static inline void bsd_free(void *addr,int type)
  7318.  
  7319.     Frees memory allocated by bsd_malloc().
  7320.  
  7321.  
  7322.    The malloc() and free() are made safe by malloc_semaphore, which
  7323. protects mallocs and frees from collisions.   It is obtained before the
  7324. actual calls to malloc() or free() and released after them.
  7325.    In addition to these functions sys/malloc.h defines macro versions for
  7326. the most usual usages.
  7327.    Initialization for these functions is done by:
  7328.  
  7329.  
  7330. BOOL malloc_init(void)
  7331.  
  7332.     Initializes the malloc_semaphore.  This must be called early in the
  7333.     initialization process, since bsd_malloc() nor bsd_free() cannot be
  7334.     called before malloc_semaphore is initialized.
  7335.  
  7336.  
  7337.  
  7338. 5.3     Concurrency Control
  7339.  
  7340.  
  7341. 5.3.1   Processor Priority Levels
  7342.  
  7343. In Unix systems the critical sections are mainly protected by raising the
  7344. processor priority level (i.e.  preventing interrupts upto a certain
  7345. level).  This crude way might hurt a real time operating system as the
  7346. AmigaOS, so it can not be implemented assuch.   Besides, the AmiTCP/IP
  7347. runs as a normal user level process which has no needed privilege to
  7348. alter the interrupt levels of the processor.
  7349.    The implementation in AmiTCP/IP is twofold; a semaphore is used in the
  7350. debugging mode and task switch prevention is used in the production
  7351. version.  Using semaphore makes debugging easy as single stepping and
  7352. tracing is possible while keeping the system alive.   The semaphore adds
  7353. certain overhead which is not acceptablein the production version, so
  7354. the prevention of the task switches is used.
  7355.    When thepreprocessor symbol DEBUG is defined the spl_semaphore is
  7356. used.  When this semaphore is free the process is at level SPL0 (user
  7357. level) and when the semaphore is allocated the process is at
  7358. ``interrupt'' level (SPLSOFTCLOCK, SPLNET or SPLIMP), effectively
  7359. disallowing anyone else to enter critical section.   When the symbol DEBUG
  7360. is not defined the functions and macrosare defined differently.  They
  7361. manipulate directly the Task Disable Nest Count (TDNextCnt field of the
  7362. SysBase).  This field is normally used by Exec functions Forbid() and
  7363. Permit() which increment and decrement the value of the field,
  7364. respectively.  Since an assembler macro is provided byCommodore for the
  7365.  
  7366. Forbid() function, the semantics of thefield cannot change in the future3.
  7367. The semantics of the TDNestCnt is littleabused by the AmiTCP/IP, however.
  7368. The value of the spl level in question is directly assigned as the value of
  7369. the field.  This is not visible outside of the AmiTCP/IP, since basically
  7370. functions which use this field either directly or indirectly (via Forbid()/Perm*
  7371.  *it())
  7372. need to return the value of the field asit was when the function was called.
  7373. This is also the semantics of the usageof the spl functions.
  7374. ________________________________
  7375.    3If it would, then all the codeusing that official macro would break.
  7376.  
  7377.  
  7378. System Manual                   AmiTCP/IP                   Section 5.3    97
  7379.  
  7380.  
  7381.  
  7382.    The spl_semaphore is initialized by the function BOOL spl_init(void)
  7383. which is called among the very first functions in the initialization
  7384. process.
  7385.    The function spl _n(int) (defined in sys/synch.h) is used to alter the
  7386. priority levels.  In the non-debugging mode there are two other
  7387. functions, too:  spl_const(), which isused with a constant (non-zero)
  7388. argument, and spl_0() which is used to switch to the level 0.  In
  7389. addition, a macro has been defined for each separate level for
  7390. portability.  The macros are as follows:
  7391.  
  7392.  
  7393. spl0() switches to the normal execution level.
  7394.  
  7395.  
  7396. splsoftclock()  is the level on which timer eventsare executed.
  7397.  
  7398.  
  7399. splnet() is the level of the network interrupts in UNIX.
  7400.  
  7401.  
  7402. splimp() is the highest of the priority levels used in the networking
  7403.     code.  For example, mbuf functions are executed at this level.
  7404.  
  7405.  
  7406.    These macros return the previous level which may then be set back with
  7407. splx(int)-macro, which sets the level tothe level given as argument.
  7408.  
  7409.  
  7410.  
  7411. 5.3.2   Sleeping Facilities
  7412.  
  7413.  
  7414. Sleeping facility is implemented by kern/kern _synch.c.  Processes sleep
  7415. on a channel, which is the key used to identify sleepers.  Usually this
  7416. is some address which is unique to the calling process.  Socket base
  7417. structure for the sleeping task is linked in the sleep queue before the
  7418. actual sleep is started.  This is how the waking task can find the
  7419. sleeper to wake up when something happens on the channel the process is
  7420. sleeping on.
  7421.    The sleepqueue is implemented as a hash table, where the channel value
  7422.  
  7423. is mapped to an index of a sleep queue with the hash function4
  7424. SLEEP_HASH() (defined in kern/kern_synch.c).
  7425.    The actual sleep is implemented by sending a time out request for the
  7426. time out duration to the timer device.  The sleep completes on the time
  7427. out, a wakeup, a break signal or users specified signal.
  7428.    Note thatall critical resources (e.g.  semaphores) must be freed
  7429. before sleeping, since otherwise the whole networking code hangs.
  7430. tsleep() does this for you.
  7431.    The functions which implement the sleep system are:
  7432.  
  7433.  
  7434. BOOL sleep_init(void)
  7435.  
  7436.     This initializes the sleep_semaphore and the sleep queues.   Thismust
  7437.     be called before any other functions of this module.
  7438.  
  7439.  
  7440. int tsleep(struct SocketBase *p, caddr_tchan,
  7441.     char *wmesg, const struct timeval *time_out)
  7442. ________________________________
  7443.    4Actually a macro.
  7444.  
  7445.  
  7446. 98    Section 5.3                  AmiTCP/IP                   System Manual
  7447.  
  7448.  
  7449.  
  7450.     This function is the function usually called by the processes5 and
  7451.     implements the sleep by using the other functions of this module.
  7452.     The caller goes to sleep for at most the time specified in the struct
  7453.     timeval argument.  chan is the channel to sleep on.  wmesg is a
  7454.     string which is marked in the socket base (p) as the reason to sleep.
  7455.     Currently no-one ever reads it, though.
  7456.  
  7457.  
  7458. void wakeup(caddr_t chan)
  7459.  
  7460.     Wakes up any sleepers on channel chan.  Searches the sleep queue for
  7461.     entries with key chan and wakes them up by first clearing the key
  7462.     (p_wchan field of the socket base structure) and then signalling the
  7463.     process with the signal of the time out message.  The usage of the
  7464.     sleep queues and the p_ fields in the socket base structures are
  7465.     protected with sleep_semaphore, which must be obtained before even
  7466.     reading the sleep queues.
  7467.  
  7468.     Note that since a task in AmigaOS may get signals anytime, the
  7469.     sleeper checks the p_wchan field on reception of thesignal and if it
  7470.     is nonzero it goes to sleep again.
  7471.  
  7472.  
  7473. void tsleep_send_timeout(struct SocketBase *p,
  7474.     const struct timeval *time_out)
  7475.  
  7476.     First ensures that the message previously sent to the timer device is
  7477.     back.  Then sends timer device a time out request for duration
  7478.     specified in time_out if it is not NULL. The requestsent is
  7479.     allocated when the library is opened.
  7480.  
  7481.  
  7482. void tsleep_abort_timeout(struct SocketBase *p,
  7483.     const struct timeval *time_out)
  7484.  
  7485.     Aborts the time out sent by the tsleep_send_timeout().  This function
  7486.     must be used when the time out must be cancelled (when the sleeper is
  7487.     waken up).
  7488.  
  7489.     This function just sets the timer reply port (timerPort field of the
  7490.     socket base) to the mode in which reception of the message does not
  7491.     cause any action.
  7492.  
  7493.  
  7494. void tsleep_enter(struct SocketBase *p,caddr_t chan, char *wmesg)
  7495.  
  7496.     Puts the caller on to a sleep queue.
  7497.  
  7498.  
  7499. int tsleep_main(struct SocketBase *p, ULONG wakemask)
  7500.  
  7501.     Waits for either time out, wakeup, break or user defined action to
  7502.     happen.  The sigIntrMask field of the socket base structure defines
  7503.     which signals will cause a break.  Return value of EINTR is returned
  7504.     if any of the signals specified in that mask are received.  In
  7505.     addition the signals are set back with SetSignal() for the user
  7506.     program to be able to detect them.  The wakemask argument specifies a
  7507.     mask for signals which should cause a return from the sleep.  In such
  7508.     case the return value ERESTART is returned.
  7509. ________________________________
  7510.    5Only WaitSelect() system calluses sleeping facilities without this
  7511.  
  7512. function.
  7513.  
  7514.  
  7515. System Manual                   AmiTCP/IP                   Section 5.4    99
  7516.  
  7517.  
  7518.  
  7519.     On exit the process is guaranteed not to be in the sleep queues any
  7520.     more, but the time out remains active if it is not the reason for
  7521.     return.  Return value on wakeup is 0 and on time out EWOULDBLOCK is
  7522.     returned.
  7523.  
  7524.  
  7525.  
  7526. 5.4     Socket  Library  Creation  Procedure
  7527.  
  7528.  
  7529. Since a new socket base is created eachtime a different task opens the
  7530. AmiTCP/IP socket library, the procedureis a bit more complicated than
  7531. on libraries where the same library baseis returned (See
  7532. [RKM Libraries 1992 ]).  There is, for example, two socket library bases
  7533. in use.  All code discussed here is located in api/amiga _api.c.
  7534.  
  7535.  
  7536.  
  7537. 5.4.1   Master Library Base
  7538.  
  7539. This is the library base that is made shown by api_show() (see section
  7540. 4.10.2).  It is placed in Exec's librarylist.  This is of type struct
  7541. Library and contains information that anoutsider can read by scanning
  7542. through the Exec library list.  Information available is version and
  7543. revision numbers and count of tasks thathave (application) library base
  7544. open.
  7545.    Master library base has only functions ELL_Open() and ELL_Expunge().
  7546. When applications opens the socket library, the Exec calls ELL_Open().
  7547. This function creates new application socket bases and increments the
  7548. reference count of open application library bases.   Ifthe calling task
  7549. has a socket base open already, a new socket base is not created but the
  7550. reference count of task's socket base isincremented and the base pointer
  7551. is returned to the caller.  This feature has many useful possibilities,
  7552. for example in intermediate libraries which need to manipulate the
  7553. sockets of the calling task.
  7554.    ELL_Expunge() does (not) do one task.  When it is called, it checks if
  7555. there is any libraries still open or ifAmiTCP/IP lets this function
  7556. execute further (in fact, currently thissecond check is sufficient since
  7557. only AmiTCP/IP can close the library andit doesn't do it until all
  7558. bases has been closed.  The next Remove() is there forfuture reference
  7559. too).  Then, the memory of the master library base is deallocated and
  7560. NULL is returned (no AmigaDOS seglist tofree).   The SIGBREAKF _CTRL_C
  7561. signal that is sent with the global varianble SB _Expunged set to TRUE
  7562. notifies api_deinit() function about the fact that now all libraries are
  7563. closed.
  7564.  
  7565.  
  7566.  
  7567. 5.4.2   Application Library Bases
  7568.  
  7569. These are the library bases that are returned to the openers of the
  7570. socket library.  In this base the Open() function is obsolete since all
  7571. OpenLibrary() calls go through the master socket base.  Exec and
  7572. AmiTCP/IP generated Expunge() calls go also through the master socket
  7573. base.
  7574.    UL_Close() is the close function for all application library bases.
  7575. First it decrements the reference countof this base and returns NULL if
  7576.  
  7577.  
  7578. 100    Section 5.5                 AmiTCP/IP                  System Manual
  7579.  
  7580.  
  7581.  
  7582. there are still references left (again,NULL informs Exec that there is
  7583. no AmigaDOS seglist needed to be removed).
  7584.    If thereare no more references to this library base, following steps
  7585. are taken to remove it from the memory:  All socket descriptors still
  7586. open are closed.  The base is removed from the AmiTCP/IP list of open
  7587. application socket bases.  The timer request is deallocated.  Then the
  7588. library base is removed from the memoryand open count of application
  7589. socket bases is decremented in the master library base.  Finally,
  7590. ELL_Expunge() is called if the open count reached zero and the LIBF_DELEXP
  7591. flag is set (by a previous ELL_Expunge() call).
  7592.  
  7593.  
  7594.  
  7595. 5.5     The  SocketBase  Structure
  7596.  
  7597.  
  7598. The SocketBase structure is defined in file api/amiga_api.h as follows:
  7599.  
  7600.  
  7601. struct SocketBase -
  7602.   struct Library         libNode;
  7603. /* "Global" Errno */
  7604.   WORD                   errnoSize;
  7605. /* -- now we are longword aligned -- */
  7606.   UBYTE *                errnoPtr; /* this points to errno */
  7607.   LONG                   defErrno;
  7608. /* Task pointer of owner task */
  7609.   struct Task *          thisTask;
  7610. /* task priority changes (WORDS so we keep structure longword aligned) */
  7611.   WORD                   myPri;       /* task's priority just after libcall */
  7612.   WORD                   libCallPri; /* task's priority during library call */
  7613. /* -- descriptor sets -- */
  7614.   WORD                   dTableSize;
  7615.   WORD                   nextDToSearch;
  7616.   struct socket **      dTable;
  7617. /* AmiTCP signal masks */
  7618.   ULONG                  sigIntrMask;
  7619.   ULONG                  sigIOMask;
  7620.   ULONG                  sigUrgMask;
  7621. /* -- these are used by tsleep()/wakeup() -- */
  7622.   char *                 p_wmesg;
  7623.   queue_chain_t          p_sleep_link;
  7624.   caddr_t                p_wchan;         /* event processis awaiting */
  7625.   struct timerequest *  tsleep_timer;
  7626.   struct MsgPort *      timerPort;
  7627. /* -- pointer to select buffer during Select() -- */
  7628.   struct newselbuf *    p_sb;
  7629. /* -- per process fields used by various'library' functions -- */
  7630. /* buffer for inet_ntoa */
  7631.   char inet_ntoa[20]; /* xxx.xxx.xxx.xxx"0 */
  7632. /* pointers for data buffers that MAY beused */
  7633.   struct DataBuffer  selitems;
  7634.   struct DataBuffer  hostents;
  7635.   struct DataBuffer  netents;
  7636.   struct DataBuffer  protoents;
  7637.   struct DataBuffer servents;
  7638. ";
  7639.  
  7640.  
  7641. System Manual                  AmiTCP/IP                 Section 5.6    101
  7642.  
  7643.  
  7644.  
  7645.    libNode is a normal library base structure and is used by the system.
  7646. Since in this implementation each openergets a task specific library
  7647. base, AmiTCP/IP links all ``user librarybases'' together using Node
  7648. field of libNode.
  7649.    When socket library function encounters an error, it saves the value of
  7650. the error to the memory location addressed by errnoPtr.  errnoSize
  7651. specifies the size of the variable pointed by the errnoPtr.  By default
  7652. errnoPtr points to the defErrno but canbe changed to point any memory
  7653. location -- usually to the global errnovariable in the context of the
  7654. user task.
  7655.    In entryof each bsdsocket.library function call, value of thisTask is
  7656. compared to the task pointer of callingtask to make sure right task is
  7657. calling the function.  This variable is also used to find library base of
  7658. some executing task.
  7659.    When taskis executing system calls in bsdsocket.library, its process
  7660. priority is changed to the same as thatof the AmiTCP/IP task in order
  7661. not to hold semaphores and block the whole network system.  If some
  7662. higher priority process becomes active and a lower priority task is
  7663. holding some vital semaphore of the AmiTCP/IP then the precess cannot
  7664. continue to run.  The manipulation of the process priorities uses myPri
  7665. and libCallPri fields of the socket base.
  7666.    dTableSize is the number of current maximum limit of socket
  7667. descriptors.  dTable is the descriptor table containingpointers to
  7668. socket structures, i.e.  sockets.  nextDToSearch makes searching of free
  7669.  
  7670. socket descriptor faster6.
  7671.    sigIntrMask is a task specific mask of the signals which should break
  7672. the Wait() call in the tsleep_main().  Reception of such signals causes
  7673. the system calls to return -1 and the error code pointed by errnoPtr to
  7674. be set to EINTR. sigIOMask field specifies the signals to send when
  7675. asynchronous notification is requested.  Signals specified in sigUrgMask
  7676. are sent when out of band data is received.   These masks implement the
  7677. functionality of the SIGIO and SIGURG signals of the Unix systems,
  7678. respectively.  All these masks can be set with the SetSocketSignals() API
  7679. call.  The default mask for the sigIntrMask specifies the signal for the
  7680. ctrl-C, other two are zero by default.
  7681.    The nextgroup of variables are used by tsleep() and wakeup().  p_wmesg
  7682. points to a string telling the reason why task is sleeping.  p _sleep_link
  7683. is used to chain library bases in the sleep queues.   Waiting channel key
  7684. is hold in variable p_wchan and data handling time outs in variables
  7685. tsleep_timer and timerPort (more about this in section 5.3.2 on page 97).
  7686.    WaitSelect() inserts one selitem on each socket it wants event
  7687. information of.  p_sb points to a newselbuf that contains these items.
  7688.    Some APIfunctions in the original environment use static buffers to
  7689. store their output.  As a shared library cannot use static buffers (to be
  7690. re-entrant), the buffers must be allocated dynamically.  The SocketBase
  7691. structure has space for the output buffer for the Inet_Ntoa() and
  7692. pointers for other needed buffers.  These buffers are allocated only when
  7693. needed.
  7694. ________________________________
  7695.    6Semantics of allocating lowestfree socket descriptor is preserved.
  7696.  
  7697.  
  7698. 102    Section 5.6                 AmiTCP/IP                  System Manual
  7699.  
  7700.  
  7701.  
  7702. 5.6     The  Application  Program  Interface
  7703.  
  7704.  
  7705.  
  7706. Most of API code is original NET/2 codetaken from BSDSS7. BSDSS mutexes
  7707. are replaced by Amiga semaphores and struct proc references are changed
  7708.  
  7709. to references to our socket library base8.
  7710.    Many functions used copyin() and copyout() to copy data around.  Those
  7711. functions copy data between system and user space (different virtual
  7712. memory mappings) in original BSD Unix system.   It is also possible that
  7713. those functions will fail e.g.  if user tries to reference illegal memory
  7714. locations.  In AmiTCP/IP system copyin() and copyout()functions are
  7715. replaced with bcopy(), arguments are thesame but the bcopy() never
  7716. fails.  Therefore some obsolete checks are removed fromthe code.
  7717.  
  7718.  
  7719.  
  7720. 5.6.1   HowAPI Functions Are Ported
  7721.  
  7722.  
  7723. Most functions in our API are ported from BSD Unix system calls.  BSD
  7724. Unix system call interface calls the actual function with three
  7725. arguments.  First is user process structure pointer.  Second contains the
  7726. given arguments and is locally named asuap structure.  Third argument is
  7727. a pointer to the return value.  The function returns error value or 0 if
  7728. no error occurred.
  7729.    The socket() function is a good example of this:
  7730.  
  7731.  
  7732.  
  7733. socket(p, uap, retval)
  7734.          struct proc *p;
  7735.          registerstruct args -
  7736.                  int      domain;
  7737.                  int      type;
  7738.                  int      protocol;
  7739.          " *uap;
  7740.          int *retval;
  7741.  
  7742.  
  7743.    The system function interface maps directly to Amiga shared library.
  7744. Since every task has socket library baseof its own, Unix process pointer
  7745.  
  7746. matches to library base pointer given inregister A69 .  uap argumentsare
  7747. passed in registers normally.  Return value is returnedin the register
  7748. D0 (as any standard C compiler does).  So the *retval was changed to a
  7749. local variable retval and removed, whennot needed.   The returned value
  7750. is -1 on error, in which case the errnois also set to indicate the error
  7751. (see file sys/errno.h for list of errorcodes), or retval, or 0 if no
  7752. other return value is needed.
  7753.    To emulate Unix system call interface, each function first obtains the
  7754. syscall_semaphore (why,see section 4.10.2 on page 90) and while this
  7755. task is holding the semaphore, no othertask can continue to execute the
  7756. ________________________________
  7757.    7BSDSS networking code is almost completely the same.
  7758.  
  7759.    8See 5.5.
  7760.  
  7761.    9All Amiga shared libraries expect them to be called relative to
  7762.  
  7763. register A6
  7764.  
  7765.  
  7766. System Manual                  AmiTCP/IP                 Section 5.7    103
  7767.  
  7768.  
  7769.  
  7770. library code10.  This means that every system call function needs to
  7771. release syscall_semaphore before returning.  To accomplish this, each
  7772. return inside the function is changed togoto Return; and at label
  7773.  
  7774. Return:  is code that releases the syscall_semaphore11 .
  7775.    The default modifications were:  changing file descriptor tables and
  7776. pointers to socket tables and pointers,respectively, removing usage of
  7777. struct fileops function pointers -- replacing them with direct socket
  7778. functions, changing copyin() and copyout() functions to bcopy()s -- no
  7779. more error checking here needed, and last, changing parameters on
  7780. tsleep() calls.
  7781.  
  7782.  
  7783.  
  7784. 5.6.2   APIFunctions Which Needed More Modifications
  7785.  
  7786. IoctlSocket()  (Former ioctl()):  Non-socket stuff removed, and ioctl code
  7787.     from soo_ioctl() inserted.
  7788.  
  7789. WaitSelect()  (Former select()) usedto count remaining time out time if
  7790.     tsleep() returned accidentally too early.  AmiTCP/IP uses the timer
  7791.     device for its time outs and the time out request is aborted only
  7792.     when it is needed again, so there is no need to send new time out
  7793.     requests (and to calculate their time out durations).  tsleep() is
  7794.     broken apart into pieces so that the time out request is sent only
  7795.     once.
  7796.  
  7797. CloseSocket()  Decreases socket's referencecount and calls soclose() to
  7798.     kill the socket if it becomes zero.
  7799.  
  7800. socket() and accept()  Added initialization of so_refcnt.  fdAlloc()
  7801.     doesn't bind fd to socket.  It is done explicitly.
  7802.  
  7803. Resolver functions  used to allocate huge amounts of stack.  Now memory is
  7804.     allocated dynamically from the head using bsd_malloc.
  7805.  
  7806.  
  7807.  
  7808. 5.7     Changes  in  Functions  Below  API  Level
  7809.  
  7810.  
  7811. Functions that API functions call are mostly functions that use struct
  7812. socket type arguments, possibly having some other arguments too.  In most
  7813. cases no modifications were needed.  There was some modifications, like
  7814. parameters for tsleep() call, which hadto be changed throughout the
  7815. code.
  7816.  
  7817.  
  7818.  
  7819. 5.7.1   Other  Changes
  7820.  
  7821. selscan()  calls soo _select() directly, and uses socket pointer instead of
  7822.     file pointer.
  7823.  
  7824. soo_select() also uses socket pointer instead of file pointer.
  7825. ________________________________
  7826.   10Not all functions require obtaining syscall_semaphore so those can continue
  7827. to run.
  7828.   11syscall_semaphore is also freed when library function does tsleep().
  7829.  
  7830.  
  7831. 104    Section 5.8                 AmiTCP/IP                  System Manual
  7832.  
  7833.  
  7834.  
  7835. socreate()  allows allsockets to be privileged.  This means that user can
  7836.     obtain raw sockets and use normally privileged port numbers.
  7837.  
  7838. sosend() uses uioread() instead of the original uiomove().  sblock() and
  7839.     sbwait() are called with library base pointer as the second argument.
  7840.  
  7841. soreceive()  uses uiowrite() instead of the original uiomove().  See above
  7842.     about the modification of call sblock() and sbwait().
  7843.  
  7844. sorflush()  calls sblock() with base pointer argument as NULL.
  7845.  
  7846. sosetopt() and sogetopt()   :  type of so_linger and so_timeo fields in
  7847.     socket structure is changed from short int to struct timeval.
  7848.     Manipulation of these data is changed accordingly.
  7849.  
  7850. sbwait() takes socket base pointer as second argument.  It is then passed
  7851.     to tsleep() (see section 5.3.2 on page 97).
  7852.  
  7853. sblock() and sb_lock():  sblock() is a macro that calls sb_lock().  Both
  7854.     take socket base pointer as second argument.  sblock() forwards that
  7855.     pointer directly to sb_lock() which, again, passes it to the
  7856.     tsleep().
  7857.  
  7858.  
  7859.  
  7860. 5.8     Agnet.device
  7861.  
  7862.  
  7863. We used the agnet.device, an SANA-II test device, to test and develop the
  7864. AmiTCP/IP network code.  The usage and features of theagnet.device are
  7865. described in the section 1.7.1, page 10.
  7866.    SANA-II is an standard network device driver interface for the Amiga
  7867. (see [SANA-II 1992 add ]).  It is an extension to the normal device
  7868. interface, which is described in the [RKM Libs & Devs 1989 ].  Device
  7869. drivers are accessed by their name fromthe system list.  Drivers may be
  7870. loaded dynamically from the disk, if they are not currently in the main
  7871. memory.  There may be several units sharing common driver code so each
  7872. (network) device is specified by an unitnumber and the device driver
  7873. name.
  7874.    We wrotethe agnet.device using the SLIP driver which Commodore has
  7875. provided as the example code for SANA-IIdrivers.   However, there was
  7876. some problems with the supplied code.  First, the SLIPdriver code
  7877. obviously follows an obsolete SANA-II draft.   There was some
  7878. modifications in the final standard e.g.  in the eventhandling and
  7879. multicast addressing.
  7880.    The provided example code was also very fragile, it did not get
  7881. compiled as such with the newer SAS C version 6.   Codedepended on some
  7882. features of the SAS C 5.10.  For example, it always expected to find
  7883. device base pointer in address registerA6.
  7884.  
  7885.  
  7886.  
  7887. 5.8.1   IO Commands
  7888.  
  7889. There is a detailed description of SANA-II device commands and functions
  7890. in [SANA-II 1992 add ].  The following IO commands are implemented in
  7891. agnet.device:
  7892.  
  7893.  
  7894. System Manual                  AmiTCP/IP                 Section 5.8    105
  7895.  
  7896.  
  7897.  
  7898. CMD_CLEAR
  7899.     This standard command should return IOERR_NOCMD when issued to
  7900.     SANA-II device.
  7901.  
  7902. CMD_INVALID
  7903.     This standard command should return IOERR_NOCMD.
  7904.  
  7905. CMD_READ
  7906.     Get the next packet available of the requested packet type.  The data
  7907.     returned (via a call to the requester-provided CopyToBuffer()
  7908.     function) is the Data Link Layer packet data only.  Raw packets are
  7909.     not supported.
  7910.  
  7911. CMD_RESET
  7912.     This standard command should return IOERR_NOCMD when issued to
  7913.     SANA-II device.
  7914.  
  7915. CMD_START
  7916.     This standard command should return IOERR_NOCMD when issued to
  7917.     SANA-II device.
  7918.  
  7919. CMD_STOP
  7920.     This standard command should return IOERR_NOCMD when issued to
  7921.     SANA-II device.
  7922.  
  7923. CMD_UPDATE
  7924.     This standard command should return IOERR_NOCMD when issued to
  7925.     SANA-II device.
  7926.  
  7927. CMD_WRITE
  7928.     Send packet to the network.  Raw packets are not supported.  Sending
  7929.     packet with a broadcast hardware address is not supported.
  7930.  
  7931. S2_BROADCAST
  7932.     Broadcast a packet to the network.  Raw packets are not supported.
  7933.  
  7934. S2_CONFIGINTERFACE
  7935.     Configure the interface.  The address field will be set depending on
  7936.     the specified hardware type.
  7937.  
  7938. S2_DEVICEQUERY
  7939.     Report the statistical information about the device.
  7940.  
  7941. S2_GETGLOBALSTATS
  7942.     Report accumulated statistics as defined in struct Sana2Devicestats.
  7943.  
  7944. S2_GETSTATIONADDRESS
  7945.     Report the ``hardware'' address for the unit.  Before the
  7946.     configuration, the current hardware address has all bits set.  The
  7947.     default hardware address is not stored anywhere.
  7948.  
  7949. S2_GETTYPESTATS
  7950.     Report accumulated statistics of the tracked packets.
  7951.  
  7952. S2_OFFLINE
  7953.     Remove interface from service.  Flush all queued IO requests.
  7954.  
  7955.  
  7956. 106    Section 5.8                 AmiTCP/IP                  System Manual
  7957.  
  7958.  
  7959.  
  7960. S2_ONEVENT
  7961.     Return when specified event(s) occur(s).
  7962.  
  7963. S2_ONLINE
  7964.     Put the interface back in service.  This command resets the unit
  7965.     statistics.
  7966.  
  7967. S2_READORPHAN
  7968.     If there is no pending CMD_READ request with the type of the received
  7969.     packet, the packet is given to first pending S2_READORPHAN request.
  7970.     The data returned (via a call to the requester-provided CopyToBuffer
  7971.     function) is the Data Link Layer packet data only.  Raw packets are
  7972.     not supported.
  7973.  
  7974. S2_TRACKTYPE
  7975.     Start tracking of the specified packet type packets.
  7976.  
  7977. S2_UNTRACKTYPE
  7978.     Stop tracking of the specified packet type packets.
  7979.  
  7980.  
  7981.  
  7982. Uninplemeted IO Commands
  7983.  
  7984. These SANA-II device commands are not supported.
  7985.  
  7986. CMD_FLUSH
  7987.     This standard command returns IOERR_NOCMD when issued to the
  7988.     agnet.device.
  7989.  
  7990. S2_ADDMULTICASTADDRESS
  7991.     This SANA-II command is not supported.  It returns IOERR_NOCMD.
  7992.  
  7993. S2_DELMULTICASTADDRESS
  7994.     This SANA-II command is not supported.  It returns IOERR_NOCMD.
  7995.  
  7996. S2_GETSPECIALSTATS
  7997.     This SANA-II command is not fully supported.  It returns an empty
  7998.     Sana2SpecialStat structure.
  7999.  
  8000.     This command should report accumulated driver specific statistics.
  8001.     This includes ethernet ``retries''.
  8002.  
  8003. S2_MULTICAST
  8004.     This SANA-II command is not supported.  It returns IOERR_NOCMD.
  8005.  
  8006.  
  8007.  
  8008. 5.8.2   Initialization Procedure
  8009.  
  8010. agnet.device must be started as a DOS process by the Run command.  The
  8011. dynamic loading is not yet implemented.  Its own startup module, init.c,
  8012. opens needed libraries, initializes device base and calls the main()
  8013. function.  Main function opens timer.device and initializes the ARexx
  8014. port; if initialization was successful,it adds the device base to the
  8015. system list.
  8016.    In the main loop the device task waits for three different events:
  8017. user or Expunge() generated break signal(SIGF _BREAK_F), ARexx messages or
  8018. user IO request messages.
  8019.  
  8020.  
  8021. System Manual                  AmiTCP/IP                 Section 5.8    107
  8022.  
  8023.  
  8024.  
  8025. 5.8.3   TheDevice Interface Functions
  8026.  
  8027. The device interface contains 6 standardlibrary calls in the device
  8028. base.  The device may be opened or closed, the IO requests may be
  8029. initiated or aborted and the system mayreclaim storage allocated by the
  8030. device driver.
  8031.    These library calls are not normally executed directly by the user code
  8032. but instead higher level convenience functions in the Exec.  The device
  8033. base library calls are made in the context of the caller, so some
  8034. synchronous IO commands may be executedlike library calls without
  8035. message passing overhead (quick IO).
  8036.    The synopsis of the functions specifies the registers where the call
  8037. parameters are passed (REG(rn)).
  8038.  
  8039.  
  8040.  
  8041. Opening an Unit
  8042.  
  8043. An IO device is opened by the Exec function call OpenDevice().  When Exec
  8044. has found the named device driver in thesystem list it calls the special
  8045. DevOpen() function from the device base.  DevOpen() function has
  8046. following synopsis:
  8047.  
  8048. ULONG ASM DevOpen(REG(a1) struct IOSana2Req *ios2,
  8049.                    REG(d0) ULONG unit, REG(d1) ULONG flags)
  8050.  
  8051.  
  8052.  
  8053.     The device open function tries to allocate and initialize various
  8054.     resources for the specified unit if the unit does not already exist.
  8055.     The initialization routine InitUnit() is called; if it returns an
  8056.     unit structure, a private buffermanagement structure is filled from
  8057.     the user provided tag list.  The user supplied IO request is filled
  8058.     with appropriate values.
  8059.  
  8060.     The promiscuous or exclusive modes are not supported.
  8061.  
  8062. struct AgnetDevUnit *InitUnit(ULONG);
  8063.  
  8064.     The initialization routine allocates an unit structure and then calls
  8065.     the configuration routine ReadConfig().  If the configuration file
  8066.     was read and interpreted without errors the lists and locks in the
  8067.     unit structure is initialized.  The unit is then put online and unit
  8068.     structure is added to the device base.
  8069.  
  8070. BOOL ReadConfig(struct AgnetDevUnit *adu)
  8071.  
  8072.     The configuration routine attempts to read in the configuration file
  8073.     for the given unit.  It strips the comments out of the file and
  8074.     provides the file as a single line to the parsing routine
  8075.     ParseConfig().  If there is no configuration file, the parsing
  8076.     routine is called with an empty line.
  8077.  
  8078.  
  8079.  
  8080. Closing an Unit
  8081.  
  8082. The accessed unit is closed after use with the Exec CloseDevice()
  8083. function.  It runs the DevClose() function from the device base.  The
  8084. call has the following synopsis:
  8085.  
  8086.  
  8087. 108    Section 5.8                 AmiTCP/IP                  System Manual
  8088.  
  8089.  
  8090.  
  8091. BPTR ASM DevClose(REG(a1) struct IOSana2Req *ios2)
  8092.  
  8093.     The device close function calls the unit close function.  If the
  8094.     device has been asked to Expunge() itself, the close function sends
  8095.     an appropriate signal to the device task.  The device task then
  8096.     performs the postponed expunge function.
  8097.  
  8098.     The DevOpen() and DevClose() calls are executed while Forbid()'den
  8099.     unless the code explicitly Wait()'s.
  8100.  
  8101.  
  8102.  
  8103. Initiating an IO Request
  8104.  
  8105.  
  8106. The DevBeginIO function from the devicebase is called to initiate an IO
  8107. command.  This call is made in the context of the requesting task (task
  8108. calling Exec functions DoIO() or SendIO()).   The DevBeginIO() call has
  8109. the following synopsis:
  8110.  
  8111.  
  8112. VOID ASM DevBeginIO(REG(a1) struct IOSana2Req *ios2)
  8113.  
  8114.     The IO request is sent to the device task for dispatching and
  8115.     execution.  Currently all IO requests are executed in the context of
  8116.     the device task, i.e.  no quick IO is supported.
  8117.  
  8118.  
  8119.  
  8120. Aborting an IO Request
  8121.  
  8122.  
  8123. Some IO requests may be aborted before they are completed by Exec
  8124. function call AbortIO().  The aborting function has thefollowing
  8125. synopsis:
  8126.  
  8127.  
  8128. VOID ASM DevAbortIO(REG(a1) struct IOSana2Req *ios2)
  8129.  
  8130.     Currently only the CMD_READ, S2_READORPHAN, CMD_WRITE, S2_BROADCAST,
  8131.     and S2_ONEVENT IO commands may be aborted.  Other IO commands are
  8132.     executed in an atomic way and can not be aborted reliably.
  8133.  
  8134.  
  8135.  
  8136. Expunging the Device
  8137.  
  8138.  
  8139. The system may reclaim the storage allocated by the device driver by
  8140. calling the DevExpunge() function.  Memory reclaiming is normally done in
  8141. a low memory situation or after a user requested memory flush.  The
  8142. expunging function has the following synopsis:
  8143.  
  8144.  
  8145. VOID ASM DevExpunge(VOID)
  8146.  
  8147.     The DevExpunge() may not Wait() because it may be called from the
  8148.     Exec function AllocMem() protected by Forbid()/Permit() pair.
  8149.  
  8150.     The DevExpunge() function call currently signals the device task,
  8151.     which performs the actual expunging by calling the DoExpunge().  Each
  8152.     unit structure is expunged by the function ExpungeUnit().
  8153.  
  8154.  
  8155. System Manual                  AmiTCP/IP                 Section 5.8    109
  8156.  
  8157.  
  8158.  
  8159. 5.8.4   Packet  Delivery
  8160.  
  8161. The packet sent to the pseudo network may be delayed or mutated randomly.
  8162. A special structure (struct DelayRequest) stores the packet type and data
  8163. during the ``transmit delay''.  The delay is implemented by sending this
  8164. structure as a the timer IO request to the timer device.  The packet
  8165. transmit functions are as follows:
  8166.  
  8167.  
  8168. VOID WritePacket(struct AgnetDevUnit *adu, struct IOSana2Req *ios2)
  8169.  
  8170.     The function checks that the unit is on line and checks for the legal
  8171.     data length.  Then the routine adds the given IO request (CMD_WRITE,
  8172.     S2_BROADCAST) into send queue.  If there is a free delay request the
  8173.     SendPacket() is called immediately.
  8174.  
  8175. VOID SendPacket(struct DelayRequest *delayed)
  8176.  
  8177.     The SendPacket() function takes an empty DelayRequest structure as
  8178.     its argument.  First, it gets a send IO request from the send queue.
  8179.     The request is immediately returned if the packet is ``lost'' during
  8180.     transmit.  This is repeated until a packet is found which is not to
  8181.     be lost.
  8182.  
  8183.     The packet data, type, length, transmission type and the address of
  8184.     the sender are then copied into the DelayRequest structure.  If
  8185.     needed, bit errors are made into packet data.
  8186.  
  8187.     If there is specified delay for the unit, the request is sent to the
  8188.     timer device.  After the delay the timer device returns request into
  8189.     the device port and it is dispatched by the ReceivePacket() function.
  8190.     If there is no delay, the ReceivePacket() is called immediately.
  8191.  
  8192. VOID ReadPacket(struct AgnetDevUnit *adu, struct IOSana2Req *ios2)
  8193.  
  8194.     The function checks that unit is online, then adds the read request
  8195.     into an appropriate queue.
  8196.  
  8197. VOID ReceivePacket(struct DelayRequest *delayed)
  8198.  
  8199.     The ReceivePacket() function calls the DoReceive() function on each
  8200.     unit the packet is destined.  It then handles the DelayRequest
  8201.     structure back to the SendPacket() function.
  8202.  
  8203. VOID DoReceive(struct AgnetDevUnit *adu,struct DelayRequest *delayed)
  8204.  
  8205.     The DoReceive() function tries to find a receive IO message waiting
  8206.     for this particular type packets.  If none is found, the first
  8207.     S2_READORPHAN IO request is selected.
  8208.  
  8209.     The CopyBack() function sets the appropriate IO request return values
  8210.     and copies the packet data to the receive buffer.
  8211.  
  8212.  
  8213.  
  8214. 5.8.5   Arexx  Interface
  8215.  
  8216. The ARexx interface is implemented by using the SimpleRexx package
  8217. provided in Commodore Native Developer Update 2.0 kit.  The Arexx
  8218. commands executed by the agnet.device are described in section 1.7.1,
  8219. page 12.
  8220.  
  8221.  
  8222. 110    Section .0                  AmiTCP/IP                   System Manual
  8223.  
  8224.  
  8225.  
  8226. LONG ParseRexx(UBYTE *arg, UBYTE **errstr, UBYTE **result)
  8227.  
  8228.     The ARexx command string is copied into a buffer and passed to the
  8229.     parser function ParseRexx().
  8230.  
  8231.     The parser allocates a DOS struct RDArgs structure for the ARexx
  8232.     command.  This structure holds the information for the DOS parsing
  8233.     functions.  The first keyword in the string is read and tokenized by
  8234.     the DOS functions ReadItem() and FindArg().
  8235.  
  8236.     The rest of the line is parsed according this token.  In the case of
  8237.     Query and Unit commands the unit number is read from the command line
  8238.     and the rest of the line is passed to the appropriate functions.
  8239.  
  8240. LONG ParseConfig(struct AgnetDevUnit *adu, struct RDArgs *rdargs,
  8241.                        STRPTR *errormessage)
  8242.     The command line stored into the RDArgs structure is parsed by the
  8243.     DOS function ReadArgs().  The parsed configuration information are
  8244.     then gathered, its legality is checked and it is stored into the unit
  8245.     structure.
  8246.  
  8247. LONG ParseQuery(struct AgnetDevUnit *adu, struct RDArgs *rdargs,
  8248.                       STRPTR *errstr, STRPTR *result)
  8249.     Like the ParseConfig(), ParseQuery() parses the command line by the
  8250.     ReadArgs().  It then fills the reply buffer by the requested
  8251.     configuration parameter values and then makes an ARexx string out of
  8252.     the buffer.  This string is then returned to the ARexx process.
  8253.  
  8254.  
  8255.  
  8256.  
  8257.  
  8258. Appendix A
  8259.  
  8260.  
  8261.  
  8262. Autodocs  for  Network Applications
  8263.  
  8264.  
  8265.  
  8266. and  Utilities
  8267.  
  8268.  
  8269.  
  8270. The AutoDoc file netutil.doc contains on-line manual pages for the
  8271. network utilities and applications.
  8272.  
  8273.  
  8274.  
  8275. Table  of  Contents
  8276.  
  8277.  
  8278.         arp : : : : : : : :: : : : : : : : : : : : : : : : : : : : : : : : : : *
  8279.  *: : : : : : : : : : 112
  8280.         ifconfig : : : : : : : : : : : : : : : : : : : : :: : : : : : : : : : :*
  8281.  * : : : : : : : : 114
  8282.         inetd : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : :*
  8283.  * : : :: : : : : : 117
  8284.         letnet  : : : : : : : : : :: : : : : : : : : : : : : : : : : : : : : : *
  8285.  *: : : : : : : : : 119
  8286.         offline : : : : : : :: : : : : : : : : : : : : : : : : : : : : : : : : *
  8287.  *: : : : : : : : : 120
  8288.         online  : : : : : : : : : :: : : : : : : : : : : : : : : : : : : : : : *
  8289.  *: : : : : : : : : 121
  8290.         ping : : : : : : : : : : : : : : : : : : : : : :: : : : : : : : : : : :*
  8291.  * : : : : : : : : : 122
  8292.         route : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : :*
  8293.  * : : :: : : : : : 126
  8294.  
  8295.  
  8296.  
  8297.                                       111
  8298.  
  8299.  
  8300. 112    Section A.1                 AmiTCP/IP                  System Manual
  8301.  
  8302.  
  8303.  
  8304. A.1     Network Utilities
  8305.  
  8306.  
  8307.  
  8308. A.1.1   arp
  8309.  
  8310.  
  8311.   NAME
  8312.         Arp- address resolution display and control
  8313.  
  8314.  
  8315.   SYNOPSIS
  8316.         arp hostname
  8317.         arp-a netname
  8318.         arp-d hostname
  8319.         arp-s hostname address [temp] [pub]
  8320.         arp-f filename
  8321.  
  8322.  
  8323.   DESCRIPTION
  8324.         Arpdisplays and modifies the Internet to hardware address
  8325.         translation tables used by the Address Resolution Protocol.
  8326.         Thehardware address is a hexadecimal string with each octet
  8327.         separated by a colon, for instance 0:12:ff:a. The length of
  8328.         theaddress must be same as the address of the specified
  8329.         interface.
  8330.  
  8331.  
  8332.   OPTIONS
  8333.          none  If no options arespecified (first form above), arp
  8334.               displays the current ARP entry for hostname.   The
  8335.               hostname must either appear in the hostname database
  8336.               (SEE hosts), or be a DARPA Internet address expressed in
  8337.               Internet standard "dot notation".
  8338.  
  8339.  
  8340.         -a    Display all current ARP entries by reading the address
  8341.               mapping table of the specified interface.
  8342.  
  8343.  
  8344.         -d   If an ARP entry exists for the host called hostname, delete
  8345.               it. This requires super-user privileges.
  8346.  
  8347.  
  8348.         -s    Create an ARP entry for the host called hostname with the
  8349.               hardware station address address. The hardware station address
  8350.               is given as six hexadecimal bytes separated by colons.  If an
  8351.               ARP entry already exists for hostname,the existing entry is
  8352.               updated with the new information.  The entry is permanent
  8353.               unless the word temp is given in the command. If the word pub
  8354.               is specified, the entry is published, which means that this
  8355.               system will act as an ARP server responding to requests for
  8356.               hostname even though the host address is not its own.
  8357.  
  8358.  
  8359.         -f    Read file filename and set multiple entries in the ARP tables.
  8360.               Entries in the file should be of the form:
  8361.  
  8362.  
  8363.                    hostname address [temp] [pub]
  8364.  
  8365.  
  8366.               Argument meanings are the same as for the -s option.
  8367.  
  8368.  
  8369.   AUTHOR
  8370.         Arpwas developed by the University of California, Berkeley, for the
  8371.         BSDUnix system.
  8372.  
  8373.  
  8374. System Manual                  AmiTCP/IP                 Section A.1    113
  8375.  
  8376.  
  8377.  
  8378.   SEE ALSO
  8379.         ifconfig, netif.protocols/arp, "net/if_arp.h"
  8380.  
  8381.  
  8382. 114    Section A.1                 AmiTCP/IP                  System Manual
  8383.  
  8384.  
  8385.  
  8386. A.1.2   ifconfig
  8387.  
  8388.  
  8389.   NAME
  8390.         ifconfig - configure network interface parameters
  8391.  
  8392.  
  8393.   SYNOPSIS
  8394.         ifconfig interface address_family [address [dest_address]] [params]
  8395.         ifconfig interface [address_family]
  8396.  
  8397.  
  8398.   DESCRIPTION
  8399.         ifconfig is used to assign an address to a network interface and/or
  8400.         configure network interface parameters.  ifconfig must be used at
  8401.         boot time to define the network address of each interface present on
  8402.         a machine.   It can also be used at other times to redefine an
  8403.         interface's address or other operating parameters.
  8404.  
  8405.  
  8406.   PARAMETERS
  8407.         interface     A string of the unit name. The device name (e.g.
  8408.                        'a2065.device') concatenated with a slash ('/') and the
  8409.                        unit number ('11'), for example 'a2065.device/11' is a
  8410.                        legal unit name.
  8411.  
  8412.  
  8413.         address_family
  8414.                       Name of protocol on which naming scheme is based.  An
  8415.                        interface can receive transmissions in differing
  8416.                        protocols, each of which may require separate naming
  8417.                        schemes.   Therefore,it is necessary to specify the
  8418.                        address_family, which may affect interpretation of the
  8419.                        remaining parameters on the command line.  The only
  8420.                        addressfamily currently supported is inet (DARPA-
  8421.                        Internet  family).
  8422.  
  8423.  
  8424.         address       Either a host name present in the host name database,
  8425.                        (SEE hosts), or a DARPA Internet address
  8426.                        expressed in Internet standard "dot notation".  The
  8427.                        host number can be omitted on 10-Mbyte/second Ethernet
  8428.                        interfaces (which use the hardware physical address),
  8429.                        and oninterfaces other than the first.
  8430.  
  8431.  
  8432.         dest_address Address of destination system.  Consists of either a
  8433.                        host name present in the host name database, hosts(4),
  8434.                        or a DARPA Internet address expressed in Internet
  8435.                        standard "dot notation".
  8436.  
  8437.  
  8438.   SWITCHES
  8439.         Thefollowing operating parameters can be specified:
  8440.  
  8441.  
  8442.          up           Mark an interface "up". Enables interface after an
  8443.                        "ifconfig down."   Occurs automatically when setting the
  8444.                        addresson an interface.  Setting this flag has no
  8445.                        effectif the hardware is "down".
  8446.  
  8447.  
  8448.          down         Mark an interface "down".  When an interface is
  8449.                        marked"down", the system will not attempt to
  8450.                        transmit messages through that interface. If
  8451.                        possible, the interface will be reset to disable
  8452.  
  8453.  
  8454. System Manual                  AmiTCP/IP                 Section A.1    115
  8455.  
  8456.  
  8457.  
  8458.                        reception as well.  This action does not
  8459.                        automatically disable routes using the interface.
  8460.  
  8461.  
  8462.         arp           Enable the use of Address Resolution Protocol in
  8463.                        mappingbetween network level addresses and link-level
  8464.                        addresses  (default).
  8465.  
  8466.  
  8467.         -arp           Disable the use of Address Resolution Protocol.
  8468.  
  8469.  
  8470.          metric n     Set the routing metric of the interface to n,
  8471.                        default0.   The routing metric is used by the routing
  8472.                        protocol (see gated(1m)).  Higher metrics have the
  8473.                        effectof making a route less favorable; metrics are
  8474.                        countedas additional hops to the destination network
  8475.                        or host.
  8476.  
  8477.  
  8478.          debug         Enable driver-dependent debugging code. This usually
  8479.                        turns on extra console error logging.
  8480.  
  8481.  
  8482.         -debug         Disable driver-dependent debugging code.
  8483.  
  8484.  
  8485.          netmask mask (Inet only) Specify how much of the address to reserve
  8486.                        for subdividing networks into sub-networks.  mask
  8487.                        includes the network part of the local address, and the
  8488.                        subnetpart which is taken from the host field of the
  8489.                        address.   mask can be specified as a single hexadecimal
  8490.                        numberwith a leading 0x, with a dot-notation Internet
  8491.                        address, or with a pseudo- network name listed in the
  8492.                        networktable networks(4).  mask contains 1's for each
  8493.                        bit position in the 32-bit address that are to be used
  8494.                        for thenetwork and subnet parts, and 0's for the host
  8495.                        part.  mask should contain at least the standard
  8496.                        networkportion, and the subnet field should be
  8497.                        contiguous with the network portion.
  8498.  
  8499.  
  8500.         broadcast     (Inet only) Specify the address that represents
  8501.                        broadcasts to the network.  The default broadcast
  8502.                        addressis the address with a host part of all 1's.
  8503.  
  8504.  
  8505.         The command:
  8506.  
  8507.  
  8508.              ifconfig interface/unit
  8509.  
  8510.  
  8511.         with no optional command arguments supplied displays the current
  8512.         configuration for interface.  If address_family is specified,
  8513.         ifconfig reports only the details specific to that address family.
  8514.  
  8515.  
  8516.   DIAGNOSTICS
  8517.  
  8518.  
  8519.         Messages indicating that the specified interface does not exist, the
  8520.         requested address is unknown, or the user is not privileged and
  8521.         tried to alter an interface's configuration.
  8522.  
  8523.  
  8524.   EXAMPLES
  8525.  
  8526.  
  8527. 116    Section A.1                 AmiTCP/IP                  System Manual
  8528.  
  8529.  
  8530.  
  8531.         ifconfig lo/0 127.0.0.1
  8532.  
  8533.  
  8534.                 This command marks internal loopback device "UP", and
  8535.                 attach an inet address 127.0.0.1 to it.
  8536.  
  8537.  
  8538.         ifconfig cslip.device/0 inet 193.102.4.144 193.102.4.129
  8539.  
  8540.  
  8541.                 This command starts the CSLIP driver, attach an
  8542.                 address 193.102.4.144 (our internet address) and a
  8543.                 destination address 193.102.4.129 (the internet
  8544.                 address of the host you are connecting) to it.
  8545.  
  8546.  
  8547.         ifconfig devs:network/a2065.device/0 inet 193.124.100.64 +
  8548.         netmask 255.255.255.192 -arp
  8549.  
  8550.  
  8551.                 This command loads an ethernet driver for the
  8552.                 Commodore A2065 Ethernet adapter unit 0, marks it
  8553.                 "up", disables ARP protocol for it, attaches an inet
  8554.                 address 193.124.100.65 to it and sets its netmask to
  8555.                 255.255.255.192.  A bitwise logical and of netmask and
  8556.                 address for the interface forms a subnet address, in
  8557.                 this case 193.124.100.64.  All packets aimed to hosts
  8558.                 with same subnet address (that is hosts 193.124.100.64
  8559.                 - 193.124.100.127) are routed to this interface.
  8560.  
  8561.  
  8562.   SEE ALSO
  8563.         netstat, hosts, arp, "net/if.h", "net/sana2tags.h"
  8564.  
  8565.  
  8566. System Manual                  AmiTCP/IP                 Section A.1    117
  8567.  
  8568.  
  8569.  
  8570. A.1.3   inetd
  8571.  
  8572.  
  8573.   NAME
  8574.          inetd - internet ``super-server''
  8575.  
  8576.  
  8577.   TEMPLATE
  8578.         inetd DEBUG/S CONFIGFILE
  8579.  
  8580.  
  8581.   DESCRIPTION
  8582.  
  8583.  
  8584.         Inetd should be run when the AmiTCP/IP protocol stack is started.
  8585.         Inetd listens for connections on certain internet sockets.  When a
  8586.         connection is found on one of its sockets, it decides what service the
  8587.         socket corresponds to, and invokes a program to service the request.
  8588.         After the program is finished, it continues to listen on the socket
  8589.         (except in some cases which will be described below).  Essentially,
  8590.         inetd allows running one daemon to invoke several others, reducing
  8591.         load on the system.
  8592.  
  8593.  
  8594.   PARAMETERS
  8595.         DEBUG       Turns on debugging.
  8596.  
  8597.  
  8598.         CONFIGFILE Specifies the configuration file name.
  8599.  
  8600.  
  8601.   CONFIGURATION
  8602.  
  8603.  
  8604.         Upon execution, inetd reads its configuration information from a
  8605.         configuration file which, by default, is AmiTCP:db/inetd.conf. There
  8606.         must be an entry for each field of the configuration file, with
  8607.         entries for each field separated by a tab or a space.  Comments are
  8608.         denoted by a ``#'' at the beginning of a line or ``;'' anywhere in the
  8609.         line. There must be an entry for each field. The fields of the
  8610.         configuration file are as follows:
  8611.  
  8612.  
  8613.               service name
  8614.               socket type
  8615.               protocol
  8616.               wait/nowait
  8617.               user
  8618.               server program
  8619.               server program name
  8620.               server program arguments
  8621.  
  8622.  
  8623.         Theservice-name entry is the name of a valid service in the
  8624.         netdatabase.   For ``internal'' services (discussed below), the service
  8625.         name must be the official name of the service.
  8626.  
  8627.  
  8628.         Thesocket-type should be one of ``stream'', ``dgram'', ``raw'',
  8629.         ``rdm'', or ``seqpacket'', depending on whether the socket is a
  8630.         stream, datagram, raw, reliably delivered message, or sequenced packet
  8631.         socket. Current system supports only stream, datagram and raw
  8632.         protocols.
  8633.  
  8634.  
  8635.         Theprotocol must be a valid protocol as given in netdatabase.
  8636.         Examples might be ``tcp'' or ``udp''.
  8637.  
  8638.  
  8639. 118    Section A.1                 AmiTCP/IP                  System Manual
  8640.  
  8641.  
  8642.  
  8643.         Thewait/nowait entry is useful for datagram sockets only (other
  8644.         sockets should have a ``nowait'' entry in this space).  If a datagram
  8645.         server connects to its peer, freeing the socket so inetd can received
  8646.         further messages on the socket, it is said to be a ``multi-threaded''
  8647.         server, and should use the ``nowait'' entry.  For datagram servers
  8648.         which process all incoming datagrams on a socket and eventually time
  8649.         out, the server is said to be ``single-threaded'' and should use a
  8650.         ``wait'' entry.  Comsat and talkd are both examples of the latter type
  8651.         ofdatagram server.
  8652.  
  8653.  
  8654.         Theuser entry should contain the user name of the user as whom the
  8655.         server should run. This field is for Unix and future compability
  8656.         only.
  8657.  
  8658.  
  8659.         Theserver-program entry should contain the pathname of the program
  8660.         which is to be executed by inetd when a request is found on its
  8661.         socket.   If theserver program is resident, the path name should be
  8662.         suppressed. If inetd provides this service internally, this entry
  8663.         should be ``internal''.
  8664.  
  8665.  
  8666.         Theserver-program-name is CLI command name for the server process. It
  8667.         isshown in the printout of ``status'' command. (Task name of the
  8668.         server process is the service and the peer address, e.g. ``echo
  8669.         [192.233.15.19]''.) This and argument entry are optional.
  8670.  
  8671.  
  8672.         Theserver program arguments should be just as arguments normally are.
  8673.  
  8674.  
  8675.         Inetd provides several ``trivial'' services internally by use of
  8676.         routines within itself.  These services are ``echo'', ``discard'',
  8677.         ``chargen'' (character generator), ``daytime'' (human readable time),
  8678.         and``time'' (machine readable time, in the form of the number of
  8679.         seconds since mid night, January 1, 1900).  All of these services are
  8680.         TCPand UDP based.  For details of these services, consult the
  8681.         appropriate RFC from the Network Information Center.
  8682.  
  8683.  
  8684.         Inetd rereads its configuration file when it receives the CTRL-F
  8685.         signal.   Services may be added, deleted or modified when the
  8686.         configuration file is reread.
  8687.  
  8688.  
  8689.   HISTORY
  8690.         Theinetd command appeared in 4.3BSD system.
  8691.  
  8692.  
  8693.   SEE ALSO
  8694.  
  8695.  
  8696. System Manual                  AmiTCP/IP                 Section A.1    119
  8697.  
  8698.  
  8699.  
  8700. A.1.4   letnet
  8701.  
  8702.   NAME
  8703.         Letnet - a simple TCP connection tool
  8704.  
  8705.  
  8706.   SYNOPSIS
  8707.         letnet  HOSTNAME/A,PORT/A
  8708.  
  8709.  
  8710.   DESCRIPTION
  8711.         Letnet connects to the specified TCP port at the specified host. The
  8712.         data read from standard input is sent to the host and data received
  8713.         from the connection is written to the standard output. Letnet
  8714.         terminates upon shutdown of the socket or receiving SIGBREAKF_CTRL_C
  8715.         signal.
  8716.  
  8717.  
  8718.   ARGUMENTS
  8719.          HOSTNAME/A
  8720.                 If there is no name service available, hostname maybe given
  8721.                 in the Internet dot notation.
  8722.  
  8723.  
  8724.          PORT/A
  8725.                 The port identifier is searched from the standard services
  8726.                 (SEE ALSO netdb/services) database. A nonstandard
  8727.                 service port may be specified in the numeric form,numbers
  8728.                 between 1---65535 are acceptable.
  8729.  
  8730.  
  8731.   AUTHOR
  8732.         Pekka Pessi, the AmiTCP/IP Group, Helsinki University of Technology
  8733.  
  8734.  
  8735.   SEE ALSO
  8736.         netdb/services, netdb/hosts
  8737.  
  8738.  
  8739. 120    Section A.1                 AmiTCP/IP                  System Manual
  8740.  
  8741.  
  8742.  
  8743. A.1.5   offline
  8744.  
  8745.   NAME
  8746.         Offline - put a SANA-II device offline
  8747.  
  8748.  
  8749.   TEMPLATE
  8750.         Offline DEV=DEVICE devicename[/unit] [UNIT unit]
  8751.  
  8752.  
  8753.   DESCRIPTION
  8754.         Offline sends the S2_OFFLINE command to the given SANA-II device
  8755.         driver and unit. This command is normally used to disconnect SANA-II
  8756.         device driver from the network adapter hardware. Device driver does
  8757.         notaccept any more read or write requests.
  8758.  
  8759.  
  8760.   EXAMPLES
  8761.         This command puts the SLIP offline, which frees then the serial port
  8762.         toyour use.
  8763.  
  8764.  
  8765.         OFFLINE  slip.device/1
  8766.  
  8767.  
  8768.   SEE ALSO
  8769.         Online,  sana2.device/S2_OFFLINE
  8770.  
  8771.  
  8772. System Manual                  AmiTCP/IP                 Section A.1    121
  8773.  
  8774.  
  8775.  
  8776. A.1.6   online
  8777.  
  8778.   NAME
  8779.         Online - put a SANA-II device online
  8780.  
  8781.  
  8782.   TEMPLATE
  8783.         Online DEV=DEVICE devicename[/unit] [UNIT unit]
  8784.  
  8785.  
  8786.   DESCRIPTION
  8787.         Online sends the S2_ONLINE command to the given SANA-II device driver
  8788.         andunit. The device driver restarts the network adapter hardware and
  8789.         accepts read and write request again.
  8790.  
  8791.  
  8792.   EXAMPLES
  8793.  
  8794.  
  8795.         This command puts the Commodore Ethernet driver online.
  8796.  
  8797.  
  8798.         Online  a2065.device/0
  8799.  
  8800.  
  8801.   SEE ALSO
  8802.         Offline, sana2.device/S2_ONLINE
  8803.  
  8804.  
  8805. 122    Section A.1                 AmiTCP/IP                  System Manual
  8806.  
  8807.  
  8808.  
  8809. A.1.7   ping
  8810.  
  8811.  
  8812.    NAME
  8813.         ping - send ICMP ECHO_REQUEST packets to network hosts
  8814.  
  8815.  
  8816.    SYNOPSIS
  8817.         ping [-dfnqrvR] [-c count] [-i wait] [-l preload] [-p pattern]
  8818.              [-s packetsize]
  8819.  
  8820.  
  8821.    DESCRIPTION
  8822.         Ping uses the ICMP protocol's mandatory ECHO_REQUEST datagram to
  8823.         elicit an ICMP ECHO_RESPONSE from a host or gateway.  ECHO_REQUEST
  8824.         datagrams (``pings'') have an IP and ICMP header, followed by a
  8825.         ``struct timeval'' and then an arbitrary number of ``pad'' bytes
  8826.         used to fill out the packet.  The options are as follows: Other
  8827.         options  are:
  8828.  
  8829.  
  8830.         -c count
  8831.                 Stop after sending (and receiving) count ECHO_RESPONSE
  8832.                 packets.
  8833.  
  8834.  
  8835.         -d      Set the SO_DEBUG option on the socketbeing used.
  8836.  
  8837.  
  8838.         -f      Flood ping.  Outputs packets as fast as they come back or
  8839.                 one hundred times per second, whichever is more.  For every
  8840.                 ECHO_REQUEST sent a period ``.'' is printed, whilefor ever
  8841.                 ECHO_REPLY received a backspace is printed.  This provides a
  8842.                 rapid display of how many packets are being dropped.   Only
  8843.                 the super-user may use this option.  This can be very hard
  8844.                 on a network and should be used with caution.
  8845.  
  8846.  
  8847.         -i wait
  8848.                 Wait wait seconds between sending each packet. Thedefault
  8849.                 is to wait for one second between each packet.  This option
  8850.                 is incompatible with the -f option.
  8851.  
  8852.  
  8853.         -l preload
  8854.                 If preload is specified, ping sends that many packets as
  8855.                 fast as possible before falling into its normal mode of
  8856.                 behavior.
  8857.  
  8858.  
  8859.         -n      Numeric output only.  No attempt will be made to lookup
  8860.                 symbolic names for host addresses.
  8861.  
  8862.  
  8863.         -p pattern
  8864.                 You may specify up to 16 ``pad'' bytes to fill outthe
  8865.                 packet you send.  This is useful for diagnosing
  8866.                 data-dependent problems in a network.  For example, ``-p
  8867.                 ff'' will cause the sent packet to be filled with all ones.
  8868.  
  8869.  
  8870.         -q      Quiet output.  Nothing is displayed except the summary lines
  8871.                 at startup time and when finished.
  8872.  
  8873.  
  8874.         -R      Record route.  Includes the RECORD_ROUTE option inthe
  8875.                 ECHO_REQUEST packet and displays the route buffer on
  8876.                 returned packets.  Note that the IP header is only large
  8877.  
  8878.  
  8879. System Manual                  AmiTCP/IP                 Section A.1    123
  8880.  
  8881.  
  8882.  
  8883.                 enough for nine such routes.  Many hosts ignore or discard
  8884.                 this option.
  8885.  
  8886.  
  8887.         -r      Bypass the normal routing tables andsend directly to a host
  8888.                 on an attached network.  If the host is not on a
  8889.                 directly-attached network, an error is returned.  This
  8890.                 option can be used to ping a local host through aninterface
  8891.                 that has no route through it.
  8892.  
  8893.  
  8894.         -s packetsize
  8895.                 Specifies the number of data bytes to be sent.  The default
  8896.                 is 56, which translates into 64 ICMP data bytes when
  8897.                 combined with the 8 bytes of ICMP header data.
  8898.  
  8899.  
  8900.         -v      Verbose output.  ICMP packets other than ECHO_RESPONSE that
  8901.                 are received are listed.
  8902.  
  8903.  
  8904.         When using ping for fault isolation, it should first be run on the
  8905.         local host, to verify that the local network interface is up and
  8906.         running.   Then,hosts and gateways further and further away should
  8907.         be``pinged''.   Round-trip times and packet loss statistics are
  8908.         computed.   If duplicate packets are received, they are not included
  8909.         inthe packet loss calculation, although the round trip time of
  8910.         these packets is used in calculating the minimum/average/maximum
  8911.         round-trip time numbers.  When the specified number of packets have
  8912.         been sent (and received) or if the program is terminated with a
  8913.         SIGINT, a brief summary is displayed.
  8914.  
  8915.  
  8916.         This program is intended for use in network testing, measurement and
  8917.         management.   Because of the load it can impose on the network, it is
  8918.         unwise to use ping during normal operations or from automated
  8919.         scripts.
  8920.  
  8921.  
  8922.    ICMP PACKET DETAILS
  8923.         AnIP header without options is 20 bytes.  An ICMP ECHO_REQUEST
  8924.         packet contains an additional 8 bytes worth of ICMP header followed
  8925.         byan arbitrary amount of data.  When a packetsize is given, this
  8926.         indicated the size of this extra piece of data (the default is 56).
  8927.         Thus the amount of data received inside of an IP packet of type ICMP
  8928.         ECHO_REPLY will always be 8 bytes more than the requested data space
  8929.         (the ICMP header).
  8930.  
  8931.  
  8932.         Ifthe data space is at least eight bytes large, ping uses the first
  8933.         eight bytes of this space to include a timestamp which it uses in
  8934.         thecomputation of round trip times.  If less than eight bytes of
  8935.         padare specified, no round trip times are given.
  8936.  
  8937.  
  8938.    DUPLICATE AND DAMAGED PACKETS
  8939.         Ping will report duplicate and damaged packets.  Duplicate packets
  8940.         should never occur, and seem to be caused by inappropriate
  8941.         link-level retransmissions.  Duplicates may occur in many situations
  8942.         andare rarely (if ever) a good sign, although the presence of low
  8943.         levels of duplicates may not always be cause for alarm.
  8944.  
  8945.  
  8946.         Damaged packets are obviously serious cause for alarm and often
  8947.  
  8948.  
  8949. 124    Section A.1                 AmiTCP/IP                  System Manual
  8950.  
  8951.  
  8952.  
  8953.         indicate broken hardware somewhere in the ping packet's path (in the
  8954.         network or in the hosts).
  8955.  
  8956.  
  8957.    TRYING DIFFERENT DATA PATTERNS
  8958.         The(inter)network layer should never treat packets differently
  8959.         depending on the data contained in the data portion.  Unfortunately,
  8960.         data-dependent problems have been known to sneak into networks and
  8961.         remain undetected for long periods of time.  In many cases the
  8962.         particular pattern that will have problems is something that doesn't
  8963.         have sufficient ``transitions'', such as all ones or all zeros, or a
  8964.         pattern right at the edge, such as almost all zeros.  It isn't
  8965.         necessarily enough to specify a data pattern of all zeros (for
  8966.         example) on the command line because the pattern that is of interest
  8967.         isat the data link level, and the relationship between what you
  8968.         type and what the controllers transmit can be complicated.
  8969.  
  8970.  
  8971.         This means that if you have a data-dependent problem you will
  8972.         probably have to do a lot of testing to find it.  If you are lucky,
  8973.         youmay manage to find a file that either can't be sent across your
  8974.         network or that takes much longer to transfer than other similar
  8975.         length files.   You can then examine this file for repeated patterns
  8976.         that you can test using the -p option of ping.
  8977.  
  8978.  
  8979.    TTL DETAILS
  8980.         TheTTL value of an IP packet represents the maximum number of IP
  8981.         routers that the packet can go through before being thrown away.  In
  8982.         current practice you can expect each router in the Internet to
  8983.         decrement the TTL field by exactly one.
  8984.  
  8985.  
  8986.         TheTCP/IP specification states that the TTL field for TCP packets
  8987.         should be set to 60, but many systems use smaller values (4.3 BSD
  8988.         uses 30, 4.2 used 15). The AmiTCP/IP uses normally TTL value 30.
  8989.  
  8990.  
  8991.         Themaximum possible value of this field is 255, and most systems
  8992.         setthe TTL field of ICMP ECHO_REQUEST packets to 255.  This is why
  8993.         youwill find you can ``ping'' some hosts, but not reach them with
  8994.         telnet or ftp.
  8995.  
  8996.  
  8997.         Innormal operation ping prints the ttl value from the packet it re-
  8998.         ceives.   When aremote system receives a ping packet, it can do one
  8999.         ofthree things with the TTL field in its response:
  9000.  
  9001.  
  9002.            Not change it; this is what Berkeley Unix systems did before the
  9003.             4.3BSD-Tahoe release.  In this case the TTL value in the
  9004.             received packet will be 255minus the number of routers in the
  9005.             round-trip path.
  9006.  
  9007.  
  9008.            Set it to 255; this is what AmiTCP/IP and current Berkeley Unix
  9009.             systems do.  In this case the TTL value in the received packet
  9010.             will be 255 minus the number of routers in the path from the
  9011.             remote system to the pinging host.
  9012.  
  9013.  
  9014.            Set it to some othervalue.   Some machines use the same value
  9015.             for ICMP packets that theyuse for TCP packets, for example
  9016.             either 30 or 60.  Others may use completely wild values.
  9017.  
  9018.  
  9019. System Manual                  AmiTCP/IP                 Section A.1    125
  9020.  
  9021.  
  9022.  
  9023.    BUGS
  9024.         Many Hosts and Gateways ignore the RECORD_ROUTE option.
  9025.  
  9026.  
  9027.         Themaximum IP header length is too small for options like
  9028.         RECORD_ROUTE to be completely useful.  There's not much that that
  9029.         canbe done about this, however.
  9030.  
  9031.  
  9032.         Flood pinging is not recommended in general, and flood pinging the
  9033.         broadcast address should only be done under very controlled
  9034.         conditions.
  9035.  
  9036.  
  9037.    SEE ALSO
  9038.         netstat,   ifconfig
  9039.  
  9040.  
  9041.    AUTHOR
  9042.         Theping command originally appeared in 4.3BSD.
  9043.  
  9044.  
  9045. 126    Section A.1                 AmiTCP/IP                  System Manual
  9046.  
  9047.  
  9048.  
  9049. A.1.8   route
  9050.  
  9051.  
  9052.    NAME
  9053.          route - manually manipulate the routing tables
  9054.  
  9055.  
  9056.    SYNOPSIS
  9057.          route [-n] [-q] [-v] command [modifiers] destination gateway
  9058.  
  9059.  
  9060.    DESCRIPTION
  9061.          Route isa program used to manually manipulate the network routing
  9062.          tables.
  9063.  
  9064.  
  9065.          Options supported by route:
  9066.  
  9067.  
  9068.          -n      Prevent attempts to print host and networknames
  9069.                  symbolically when reporting actions.
  9070.  
  9071.  
  9072.          -v      (verbose) Print additional details.
  9073.  
  9074.  
  9075.          -q      Suppress all output.
  9076.  
  9077.  
  9078.          Commandsaccepted by route:
  9079.  
  9080.  
  9081.          add         Add a route.
  9082.          delete      Delete a specific route.
  9083.  
  9084.  
  9085.          The destination is the destination host or network, gateway is the
  9086.          next-hopgateway to which packets should be addressed. Routes to a
  9087.          particular host are distinguished from those to a network by
  9088.          interpreting the Internet address associated with destination. The
  9089.          optionalmodifiers -net and -host force the destination to be
  9090.          interpreted as a network or a host, respectively.  Otherwise, if the
  9091.          destination has a ``local address part'' of INADDR_ANY, or if the
  9092.          destination is the symbolic name of a network, then the route is
  9093.          assumed to be to a network; otherwise, it is presumed to be a route
  9094.          to a host.
  9095.  
  9096.  
  9097.          For example, 128.32 is interpreted as -host 128.0.0.32; 128.32.130
  9098.          is interpreted as -host 128.32.0.130; -net 128.32 is interpreted as
  9099.          128.32.0.0; and -net 128.32.130 is interpreted as 128.32.130.0.
  9100.  
  9101.  
  9102.          To add adefault route, give the destination as 'default'.
  9103.  
  9104.  
  9105.          If the route is via an interface rather than via a gateway, the
  9106.          -interface modifier should be specified; the gateway given is the
  9107.          address of this host on the common network, indicating the interface
  9108.          to be used for transmission.
  9109.  
  9110.  
  9111.          The optional -netmask qualifier is used to specify the netmask of
  9112.          the interface. One specifies an additional ensuing address parameter
  9113.          (to be interpreted as a network mask).  The implicit network mask
  9114.          generatedcan be overridden by making sure this option follows the
  9115.          destination  parameter.
  9116.  
  9117.  
  9118.          All symbolic names specified for a destination or gateway are looked
  9119.          up firstas a host name using gethostbyname(). If this lookup fails,
  9120.  
  9121.  
  9122. System Manual                  AmiTCP/IP                 Section A.1    127
  9123.  
  9124.  
  9125.  
  9126.          getnetbyname() is then used to interpret the name as that of a
  9127.          network.
  9128.  
  9129.  
  9130.    DIAGNOSTICS
  9131.          add [host_ network ] %s: gateway %s flags %x
  9132.                  The specified route is being added to the tables. The values
  9133.                  printed are from the routing table entry supplied in the
  9134.                  IoctlSocket() call. If the gateway address used was not the
  9135.                  primary address of the gateway (the first one returned by
  9136.                  gethostbyname()), the gateway address is printed numerically
  9137.                  as well as symbolically.
  9138.  
  9139.  
  9140.          delete [host _ network ] %s: gateway %s flags %x
  9141.                  As above, but when deleting an entry.
  9142.  
  9143.  
  9144.          Network is unreachable
  9145.                  An attempt to add a route failed because the gateway listed
  9146.                  was not on a directly-connected network.  The next-hop
  9147.                  gateway must be given.
  9148.  
  9149.  
  9150.          not in table
  9151.                  A delete operation was attempted for an entry which wasn't
  9152.                  present in the tables.
  9153.  
  9154.  
  9155.          routing table overflow
  9156.                  An add operation was attempted, but the system was low on
  9157.                  resources and was unable to allocate memory to create the
  9158.                  new entry.
  9159.  
  9160.  
  9161.    SEE ALSO
  9162.          ifconfig, protocols/routing
  9163.  
  9164.  
  9165.    HISTORY
  9166.          The routecommand appeared in 4.2BSD.
  9167.  
  9168.  
  9169.  
  9170.  
  9171.  
  9172. Appendix B
  9173.  
  9174.  
  9175.  
  9176. API  Function  Reference
  9177.  
  9178.  
  9179.  
  9180. This appendix is a complete reference tothe functions and concepts
  9181. provided by the AmiTCP/IP system.
  9182.  
  9183.  
  9184.  
  9185. Table  of  Contents
  9186.  
  9187.  
  9188.  
  9189.    Standard BSD Style Socket Functions
  9190.         accept  : : : : : : : : : :: : : : : : : : : : : : : : : : : : : : : : *
  9191.  *: : : : : : : : : 130
  9192.         bind : : : : : : : : : : : : : : : : : : : : : :: : : : : : : : : : : :*
  9193.  * : : : : : : : : : 132
  9194.         CloseSocket : : : : :: : : : : : : : : : : : : : : : : : : : : : : : : *
  9195.  *: : : : : : : : 133
  9196.         connect : : : : : : :: : : : : : : : : : : : : : : : : : : : : : : : : *
  9197.  *: : : : : : : : : 134
  9198.         Dup2Socket  : : : : : : : : :: : : : : : : : : : : : : : : : : : : : : *
  9199.  *: : : : : : : : 136
  9200.         getpeername : : : : :: : : : : : : : : : : : : : : : : : : : : : : : : *
  9201.  *: : : : : : : : 137
  9202.         getsockname : : : : :: : : : : : : : : : : : : : : : : : : : : : : : : *
  9203.  *: : : : : : : : 138
  9204.         getsockopt  : : : : : : : : :: : : : : : : : : : : : : : : : : : : : : *
  9205.  *: : : : : : : : 139
  9206.         IoctlSocket : : : : :: : : : : : : : : : : : : : : : : : : : : : : : : *
  9207.  *: : : : : : : : 142
  9208.         listen  : : : : : : : : : :: : : : : : : : : : : : : : : : : : : : : : *
  9209.  *: : : : : : : : : 144
  9210.         recv : : : : : : : : : : : : : : : : : : : : : :: : : : : : : : : : : :*
  9211.  * : : : : : : : : : 145
  9212.         recvfrom : : : : : : : : : : : : : : : : : : : : :: : : : : : : : : : :*
  9213.  * : : : : : : : : 145
  9214.         select  : : : : : : : : : :: : : : : : : : : : : : : : : : : : : : : : *
  9215.  *: : : : : : : : : 147
  9216.         send : : : : : : : : : : : : : : : : : : : : : :: : : : : : : : : : : :*
  9217.  * : : : : : : : : : 150
  9218.         sendto  : : : : : : : : : :: : : : : : : : : : : : : : : : : : : : : : *
  9219.  *: : : : : : : : : 150
  9220.         setsockopt  : : : : : : : : :: : : : : : : : : : : : : : : : : : : : : *
  9221.  *: : : : : : : : 139
  9222.         shutdown : : : : : : : : : : : : : : : : : : : : :: : : : : : : : : : :*
  9223.  * : : : : : : : : 152
  9224.         socket  : : : : : : : : : :: : : : : : : : : : : : : : : : : : : : : : *
  9225.  *: : : : : : : : : 153
  9226.         WaitSelect  : : : : : : : : :: : : : : : : : : : : : : : : : : : : : : *
  9227.  *: : : : : : : : 147
  9228.  
  9229.  
  9230.    Other BSD Functions Related to Sockets
  9231.         getdtablesize : : : : : : : : : : : : : : : : : : : : : : : : : : : : :*
  9232.  * : : : :: : : 156
  9233.         Syslog  : : : : : : : : : :: : : : : : : : : : : : : : : : : : : : : : *
  9234.  *: : : : : : : : : 157
  9235.  
  9236.  
  9237.    Network Data and Address Manipulation
  9238.         inet_addr : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : :*
  9239.  * : : : : : : :: 159
  9240.         Inet_LnaOf: : : : : : : : : : : : : : : : : : : : : : : : : : : : : : :*
  9241.  * : : : :: : : : 159
  9242.         inet_lnaof: : : : : : : : : : : : : : : : : : : : : : : : : : : : : : :*
  9243.  * : : : :: : : : 159
  9244.  
  9245.  
  9246.  
  9247.                                       128
  9248.  
  9249.  
  9250. System Manual                  AmiTCP/IP                 Section B.0    129
  9251.  
  9252.  
  9253.  
  9254.         inet_MakeAddr : : : : : : : : : : : : : : : : : : : : : : : : : : : : :*
  9255.  * : : : : : : :159
  9256.         inet_makeaddr : : : : : : : : : : : : : : : : : : : : : : : : : : : : :*
  9257.  * : : : : : : :159
  9258.         Inet_NetOf: : : : : : : : : : : : : : : : : : : : : : : : : : : : : : :*
  9259.  * : : : :: : : : 159
  9260.         inet_netof: : : : : : : : : : : : : : : : : : : : : : : : : : : : : : :*
  9261.  * : : : :: : : : 159
  9262.         inet_network : : : : : : : : : : : : : : : : : : : : : : :: : : : : : :*
  9263.  * : : : : : : : 159
  9264.         Inet_NtoA : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : :*
  9265.  * : : : : : : :: 159
  9266.         inet_ntoa : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : :*
  9267.  * : : : : : : :: 159
  9268.  
  9269.  
  9270.    Network, Protocol and Service Queries
  9271.         gethostbyaddr : : : : : : : : : : : : : : : : : : : : : : : : : : : : :*
  9272.  * : : : :: : : 162
  9273.         gethostbyname : : : : : : : : : : : : : : : : : : : : : : : : : : : : :*
  9274.  * : : : :: : : 162
  9275.         getnetbyaddr : : : : : : : : : : : : : : : : : : :: : : : : : : : : : :*
  9276.  * : : : : : : : 164
  9277.         getnetbyname : : : : : : : : : : : : : : : : : : :: : : : : : : : : : :*
  9278.  * : : : : : : : 164
  9279.         getprotobyname  : : : : : : :: : : : : : : : : : : : : : : : : : : : : *
  9280.  *: : : : : : : 166
  9281.         getprotobynumber : : : : : : : : : : : : : : : : : :: : : : : : : : : :*
  9282.  * : : : : : : 166
  9283.         getservbyname : : : : : : : : : : : : : : : : : : : : : : : : : : : : :*
  9284.  * : : : :: : : 167
  9285.         getservbyport : : : : : : : : : : : : : : : : : : : : : : : : : : : : :*
  9286.  * : : : :: : : 167
  9287.  
  9288.  
  9289.    AmiTCP/IP Specific Extensions
  9290.         Errno : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : :*
  9291.  * : : :: : : : : : 169
  9292.         ObtainSocket : : : : : : : : : : : : : : : : : : :: : : : : : : : : : :*
  9293.  * : : : : : : : 170
  9294.         ReleaseCopyOfSocket : :: : : : : : : : : : : : : : : : : : : : : : : : *
  9295.  *: : : : : : 171
  9296.         ReleaseSocket : : : : : : : : : : : : : : : : : : : : : : : : : : : : :*
  9297.  * : : : :: : : 172
  9298.         SetDTableSize : : : : : : : : : : : : : : : : : : : : : : : : : : : : :*
  9299.  * : : : :: : : 173
  9300.         SetErrnoPtr : : : : :: : : : : : : : : : : : : : : : : : : : : : : : : *
  9301.  *: : : : : : : : 174
  9302.         SetSocketSignals : : : : : : : : : : : : : : : : : :: : : : : : : : : :*
  9303.  * : : : : : : 175
  9304.  
  9305.  
  9306. 130    Section B.1                 AmiTCP/IP                  System Manual
  9307.  
  9308.  
  9309.  
  9310. B.1     Standard  BSD  Style Socket  Functions
  9311.  
  9312.  
  9313.  
  9314. B.1.1   accept()
  9315.  
  9316.  
  9317.    NAME
  9318.          accept -accept a connection on a socket
  9319.  
  9320.  
  9321.    SYNOPSIS
  9322.          #include <sys/types.h>
  9323.          #include <sys/socket.h>
  9324.  
  9325.  
  9326.          ns = accept(s, addr, addrlen)
  9327.          D0          D0 A0     A1
  9328.  
  9329.  
  9330.          long accept(long, struct sockaddr *, long *);
  9331.  
  9332.  
  9333.    FUNCTION
  9334.          The  argument  s  is a  socket  that  has  been created with
  9335.          socket(),bound to an  address  with bind(), and  is listen-
  9336.          ing for connections after a listen().  accept() extracts the
  9337.          first  connection  on  the  queue  of  pending  connections,
  9338.          creates anew socket with the same properties of s and allo-
  9339.          cates a new socket descriptor for the socket.  If no pending
  9340.          connections are present on the  queue, and the socket is not
  9341.          marked  as non-blocking, accept() blocks the caller  until a
  9342.          connection is present.  If the socket is marked non-blocking
  9343.          and  no pending  connections  are  present  on  the  queue,
  9344.          accept()returns  an error as described below.  The accepted
  9345.          socket isused to read and write data to and from the socket
  9346.          which connected to  this one; it is not used to  accept more
  9347.          connections.   The original socket s remains open for accept-
  9348.          ing further connections.
  9349.  
  9350.  
  9351.          The argument addr is a result parameter that  is  filled  in
  9352.          with  the address of the connecting entity, as known to the
  9353.          communications layer.  The exact format of the addr  parame-
  9354.          ter  is determined by the domain in which the communication
  9355.          is occurring.  The addrlen is a value-result  parameter;  it
  9356.          should  initially  contain the amount of space pointed to by
  9357.          addr; onreturn it will contain the actual length (in bytes)
  9358.          of    the   address    returned.    This  call  is  used  with
  9359.          connection-based socket types, currently with SOCK_STREAM.
  9360.  
  9361.  
  9362.          It is possible to select() a socket  for  the  purposes  of
  9363.          doing anaccept() by selecting it for read.
  9364.  
  9365.  
  9366.    RETURN VALUES
  9367.          accept()returns a non-negative descriptor for the  accepted
  9368.          socket onsuccess.   Onfailure, it returns -1 and sets errno
  9369.          to indicate the error.
  9370.  
  9371.  
  9372. System Manual                  AmiTCP/IP                 Section B.1    131
  9373.  
  9374.  
  9375.  
  9376.    ERRORS
  9377.          EBADF         - The descriptoris invalid.
  9378.  
  9379.  
  9380.          EINTR         - The operation was interrupted by a break
  9381.                          signal.
  9382.  
  9383.  
  9384.          EOPNOTSUPP    - The referencedsocket is not of type
  9385.                          SOCK_STREAM.
  9386.  
  9387.  
  9388.          EWOULDBLOCK   - The socket is marked non-blocking and no con-
  9389.                          nections are present to be accepted.
  9390.  
  9391.  
  9392.    SEE ALSO
  9393.          bind(), connect(), listen(), select(), SetSocketSignals(),
  9394.          socket()
  9395.  
  9396.  
  9397. 132    Section B.1                 AmiTCP/IP                  System Manual
  9398.  
  9399.  
  9400.  
  9401. B.1.2   bind()
  9402.  
  9403.    NAME
  9404.          bind - bind a name to a socket
  9405.  
  9406.  
  9407.    SYNOPSIS
  9408.          #include <sys/types.h>
  9409.          #include <sys/socket.h>
  9410.  
  9411.  
  9412.          success =bind(s, name, namelen)
  9413.          D0              D0 A0    D1
  9414.  
  9415.  
  9416.          long bind(long, struct sockaddr *, long);
  9417.  
  9418.  
  9419.    FUNCTION
  9420.          bind() assigns a name to an unnamed socket.  When  a  socket
  9421.          is created with socket(2) it exists in a name space (address
  9422.          family) but has no name assigned.  bind() requests that  the
  9423.          name pointed to by name be assigned to the socket.
  9424.  
  9425.  
  9426.    RETURN VALUES
  9427.          0  - on success.
  9428.  
  9429.  
  9430.          -1 - on failure and sets errno to indicate the error.
  9431.  
  9432.  
  9433.    ERRORS
  9434.          EACCES            - The requested address is protected,  and
  9435.                               the  current user has inadequate permis-
  9436.                               sion to access it.
  9437.  
  9438.  
  9439.          EADDRINUSE         - The specified address is already in use.
  9440.  
  9441.  
  9442.          EADDRNOTAVAIL      - The specified address is  not  available
  9443.                               from the local machine.
  9444.  
  9445.  
  9446.          EBADF              -s is not a valid descriptor.
  9447.  
  9448.  
  9449.          EINVAL            - namelen is  not  the  size  of  a  valid
  9450.                               address  for  the specified address fam-
  9451.                               ily.
  9452.  
  9453.  
  9454.                               The  socket  is  already  bound  to   an
  9455.                               address.
  9456.  
  9457.  
  9458.    SEE ALSO
  9459.          connect(), getsockname(), listen(), socket()
  9460.  
  9461.  
  9462.    NOTES
  9463.          The rulesused in name binding  vary  between  communication
  9464.          domains.
  9465.  
  9466.  
  9467. System Manual                  AmiTCP/IP                 Section B.1    133
  9468.  
  9469.  
  9470.  
  9471. B.1.3   CloseSocket()
  9472.  
  9473.    NAME
  9474.          CloseSocket - delete a socket descriptor
  9475.  
  9476.  
  9477.    SYNOPSIS
  9478.          success =CloseSocket(s)
  9479.          D0                     D0
  9480.  
  9481.  
  9482.          long CloseSocket(long);
  9483.  
  9484.  
  9485.    FUNCTION
  9486.          CloseSocket() deletes  a  descriptor  from the  library base
  9487.          socket reference table.    Ifs is the last reference  to the
  9488.          underlying object, then the object  will  be deactivated and
  9489.          socket  (see socket()),  associated naming  information  and
  9490.          queued data are discarded.
  9491.  
  9492.  
  9493.          All sockets are automatically closed when the socket library
  9494.          is closed, but closing sockets as soon as possible is
  9495.          recommended to save system resources.
  9496.  
  9497.  
  9498.    RETURN VALUES
  9499.           0   on success.
  9500.  
  9501.  
  9502.          -1   on failure and sets errnoto indicate the error.
  9503.  
  9504.  
  9505.    ERRORS
  9506.          EBADF              -s is not an active socket descriptor.
  9507.  
  9508.  
  9509.          EINTR              -linger on close was interrupted.
  9510.                               The socket is closed, however.
  9511.  
  9512.  
  9513.    SEE ALSO
  9514.          accept(),SetSocketSignals(), shutdown(), socket(),
  9515.          exec.library/CloseLibrary()
  9516.  
  9517.  
  9518. 134    Section B.1                 AmiTCP/IP                  System Manual
  9519.  
  9520.  
  9521.  
  9522. B.1.4   connect()
  9523.  
  9524.  
  9525.  
  9526.    NAME
  9527.          connect -initiate a connection on a socket
  9528.  
  9529.  
  9530.    SYNOPSIS
  9531.          #include <sys/types.h>
  9532.          #include <sys/socket.h>
  9533.  
  9534.  
  9535.          success =connect(s, name, namelen)
  9536.          D0                 D0 A0    D1
  9537.  
  9538.  
  9539.          long connect(long, struct sockaddr *, long);
  9540.  
  9541.  
  9542.    FUNCTION
  9543.          The parameter s is a socket.  If it  is of  type SOCK_DGRAM,
  9544.          then  this call specifies the peer with which the  socket is
  9545.          to be associated;  this address  is that  to which datagrams
  9546.          are  to be sent, and  the only address from which  datagrams
  9547.          are to bereceived.   Ifit is of type SOCK_STREAM, then this
  9548.          call attempts  to make a connection  to another socket.  The
  9549.          other socket is specified by name which is an address in the
  9550.          communications space of  the  socket.   Each  communications
  9551.          space interprets the  name parameter in  its  own way.  Gen-
  9552.          erally, stream sockets may successfully connect() only once;
  9553.          datagramsockets may use connect() multiple  times to change
  9554.          their association.  Datagram sockets may dissolve the  asso-
  9555.          ciation by connecting to  an invalid address, such as a null
  9556.          address.
  9557.  
  9558.  
  9559.    RETURN VALUES
  9560.           0   on success.
  9561.  
  9562.  
  9563.          -1   on failure and sets errnoto indicate the error.
  9564.  
  9565.  
  9566.    ERRORS
  9567.          EADDRINUSE         - The address is already in use.
  9568.  
  9569.  
  9570.          EADDRNOTAVAIL      - The specified address is  not  available
  9571.                               on the remote machine.
  9572.  
  9573.  
  9574.          EAFNOSUPPORT       - Addresses in the specified address   fam-
  9575.                               ily cannot be used with this socket.
  9576.  
  9577.  
  9578.          EALREADY          - The socket is non-blocking and a  previ-
  9579.                               ous  connection attempt has not yet been
  9580.                               completed.
  9581.  
  9582.  
  9583.          EBADF              -s is not a valid descriptor.
  9584.  
  9585.  
  9586.          ECONNREFUSED       - The attempt to  connect  was forcefully
  9587.  
  9588.  
  9589. System Manual                  AmiTCP/IP                 Section B.1    135
  9590.  
  9591.  
  9592.  
  9593.                               rejected.   The  calling  program should
  9594.                               CloseSocket() the socket descriptor, and
  9595.                               issue another socket()  call to obtain a
  9596.                               new descriptor before attempting another
  9597.                               connect() call.
  9598.  
  9599.  
  9600.          EINPROGRESS        - The socket is non-blocking and the  con-
  9601.                               nection cannot be completed immediately.
  9602.                               It is possible to select()  for  comple-
  9603.                               tion  by  selecting the socket for writ-
  9604.                               ing.
  9605.  
  9606.  
  9607.          EINTR              -The operation was interrupted by a break
  9608.                               signal.
  9609.  
  9610.  
  9611.          EINVAL            - namelen is  not  the  size  of  a  valid
  9612.                               address  for  the specified address fam-
  9613.                               ily.
  9614.  
  9615.  
  9616.          EISCONN             The socket is already connected.
  9617.  
  9618.  
  9619.          ENETUNREACH        - The network is not reachable  from  this
  9620.                               host.
  9621.  
  9622.  
  9623.          ETIMEDOUT         - Connection    establishment    timed    out
  9624.                               without establishing a connection.
  9625.  
  9626.  
  9627.    SEE ALSO
  9628.          accept(),CloseSocket(), connect(), getsockname(), select(),
  9629.          socket()
  9630.  
  9631.  
  9632. 136    Section B.1                 AmiTCP/IP                  System Manual
  9633.  
  9634.  
  9635.  
  9636. B.1.5   Dup2Socket()
  9637.  
  9638.    NAME
  9639.         Dup2Socket - duplicate a socket descriptor
  9640.  
  9641.  
  9642.    SYNOPSIS
  9643.  
  9644.  
  9645.         newfd = Dup2Socket(fd1, fd2)
  9646.         D0                  D0   D1
  9647.  
  9648.  
  9649.         long Dup2Socket(long, long);
  9650.  
  9651.  
  9652.    DESCRIPTION
  9653.         Dup2Socket() duplicates an existing socket descriptor.
  9654.         theargument fd1 is small non-negative value that indexes
  9655.         thesocket on SocketBase descriptor table. The value must
  9656.         beless than the size of the table, which is returned by
  9657.         getdtablesize(). fd2 specifies the desired value of the new
  9658.         descriptor. If descriptor fd2 is already in use, it is
  9659.         first deallocated as if it were closed by CloseSocket(). If
  9660.         thevalue if fd2 is -1, the new descriptor used and returned
  9661.         isthe lowest numbered descriptor that is not currently in
  9662.         useby the SocketBase.
  9663.  
  9664.  
  9665.    RETURN VALUES
  9666.         Dup2Socket() returns a new descriptor on  success. On failure
  9667.         -1is returned and errno is set to indicate the error.
  9668.  
  9669.  
  9670.    ERRORS
  9671.         EBADF           fd1 or fd2 is not a valid active descriptor.
  9672.  
  9673.  
  9674.         EMFILE          Too many descriptors are active.
  9675.  
  9676.  
  9677.    SEE ALSO
  9678.         accept(), CloseSocket(), getdtablesize(), SetDtableSize(),
  9679.         socket()
  9680.  
  9681.  
  9682. System Manual                  AmiTCP/IP                 Section B.1    137
  9683.  
  9684.  
  9685.  
  9686. B.1.6   getpeername()
  9687.  
  9688.    NAME
  9689.          getpeername - get name of connected peer
  9690.  
  9691.  
  9692.    SYNOPSIS
  9693.          success =  getpeername(s, name, namelen)
  9694.          D0                      D0 A0    A1
  9695.  
  9696.  
  9697.          long getpeername(long, struct sockaddr *, long *);
  9698.  
  9699.  
  9700.    FUNCTION
  9701.          getpeername() returns the name  of  the  peer  connected  to
  9702.          socket  s.    The long  pointed  to  by the namelen parameter
  9703.          should be  initialized  to  indicate  the  amount  of  space
  9704.          pointed to  by name.  On return it contains the actual size
  9705.          of the name returned (in bytes).  The name is  truncated  if
  9706.          the buffer provided is too small.
  9707.  
  9708.  
  9709.    RETURN VALUE
  9710.          A 0 is returned if the call succeeds, -1 if it fails.
  9711.  
  9712.  
  9713.    ERRORS
  9714.          EBADF         - The argument sis not a valid descriptor.
  9715.  
  9716.  
  9717.          ENOBUFS      - Insufficient resources were available in   the
  9718.                          system to perform the operation.
  9719.  
  9720.  
  9721.          ENOTCONN     - The socket is not connected.
  9722.  
  9723.  
  9724.    SEE ALSO
  9725.          accept(),bind(), getsockname(), socket()
  9726.  
  9727.  
  9728. 138    Section B.1                 AmiTCP/IP                  System Manual
  9729.  
  9730.  
  9731.  
  9732. B.1.7   getsockname()
  9733.  
  9734.    NAME
  9735.          getsockname - get socket name
  9736.  
  9737.  
  9738.    SYNOPSIS
  9739.  
  9740.  
  9741.          success =getsockname(s, name, namelen)
  9742.          D0                     D0 A0    A1
  9743.  
  9744.  
  9745.          long getsockname(long, struct sockaddr *, long *);
  9746.  
  9747.  
  9748.    FUNCTION
  9749.          getsockname() returns the current  name  for  the  specified
  9750.          socket.   The  namelen  parameter  should  be initialized to
  9751.          indicatethe amount of space pointed to by name.  On  return
  9752.          it contains the actual size of the name returned (in bytes).
  9753.  
  9754.  
  9755.    DIAGNOSTICS
  9756.          A 0 is returned if the call succeeds, -1 if it fails.
  9757.  
  9758.  
  9759.    ERRORS
  9760.          The callsucceeds unless:
  9761.  
  9762.  
  9763.          EBADF          s is not a valid descriptor.
  9764.  
  9765.  
  9766.          ENOBUFS         Insufficient resources were available in  the
  9767.                          system to perform the operation.
  9768.  
  9769.  
  9770.    SEE ALSO
  9771.          bind(), getpeername(), socket()
  9772.  
  9773.  
  9774. System Manual                  AmiTCP/IP                 Section B.1    139
  9775.  
  9776.  
  9777.  
  9778. B.1.8   getsockopt()
  9779.  
  9780.  
  9781.  
  9782.    NAME
  9783.          getsockopt, setsockopt - get and set options on sockets
  9784.  
  9785.  
  9786.    SYNOPSIS
  9787.          #include <sys/types.h>
  9788.          #include <sys/socket.h>
  9789.  
  9790.  
  9791.          success =  getsockopt(s, level, optname, optval, optlen)
  9792.          D0                     D0 D1     D2        A0      A1
  9793.  
  9794.  
  9795.          long getsockopt(long, long, long, caddr_t, long *);
  9796.  
  9797.  
  9798.          success =  setsockopt(s, level, optname, optval, optlen)
  9799.          D0                     D0 D1     D2        A0      D3
  9800.  
  9801.  
  9802.          long setsockopt(long, long, long, caddr_t, long);
  9803.  
  9804.  
  9805.    FUNCTION
  9806.          getsockopt() and setsockopt() manipulate options  associated
  9807.          with  a socket.  Options may exist at multiple protocol lev-
  9808.          els; theyare always present  at  the  uppermost  ``socket''
  9809.          level.
  9810.  
  9811.  
  9812.          When manipulating socket options  the  level  at  which  the
  9813.          option resides and the name of the option must be specified.
  9814.          To manipulate options at  the  ``socket''  level,  level  is
  9815.          specifiedas SOL_SOCKET.  To manipulate options at any other
  9816.          level theprotocol number of the appropriate  protocol  con-
  9817.          trolling the  option is supplied.  For example, to indicate
  9818.          that an option is to be interpreted  by  the  TCP  protocol,
  9819.          level  should  be  set  to  the  protocol number of TCP.
  9820.  
  9821.  
  9822.          The parameters optval and optlen are used to  access  option
  9823.          values  for  setsockopt().  For getsockopt() they identify a
  9824.          buffer inwhich the value for the requested option(s) are to
  9825.          be  returned.    For  getsockopt(),  optlen is a value-result
  9826.          parameter,  initially  containing  the  size  of  the  buffer
  9827.          pointed to by optval, and modified on return to indicate the
  9828.          actual size of the value returned.  If no option value is to
  9829.          be supplied or returned, optval may be supplied as 0.
  9830.  
  9831.  
  9832.          optname and any specified options are  passed  uninterpreted
  9833.          to  the appropriate protocol module for interpretation.  The
  9834.          include file  <sys/socket.h>    contains    definitions    for
  9835.          ``socket'' level options, described below.  Options at other
  9836.          protocol levels  vary  in  format  and  name.
  9837.  
  9838.  
  9839.          Most socket-level options take an int parameter for  optval.
  9840.          For setsockopt(), the parameter should be non-zero to enable
  9841.  
  9842.  
  9843. 140    Section B.1                 AmiTCP/IP                  System Manual
  9844.  
  9845.  
  9846.  
  9847.          a booleanoption, or zero if the option is to  be  disabled.
  9848.  
  9849.  
  9850.          SO_LINGER   uses  a  struct  linger  parameter,  defined  in
  9851.          <sys/socket.h>, which specifies the  desired  state  of  the
  9852.          option and the linger interval (see below).
  9853.  
  9854.  
  9855.          The following options are recognized at  the  socket  level.
  9856.          Except  as noted, eachmay be examined with getsockopt() and
  9857.          set withsetsockopt().
  9858.  
  9859.  
  9860.               SO_DEBUG           - toggle    recording    of    debugging
  9861.                                    information
  9862.               SO_REUSEADDR      - toggle local address reuse
  9863.               SO_KEEPALIVE      - toggle keep connections alive
  9864.               SO_DONTROUTE      - toggle routing bypass for  outgoing
  9865.                                    messages
  9866.               SO_LINGER          - linger on close if data present
  9867.               SO_BROADCAST      - toggle    permission    to    transmit
  9868.                                    broadcast messages
  9869.               SO_OOBINLINE      - toggle  reception  of   out-of-band
  9870.                                    data in band
  9871.               SO_SNDBUF          - set buffer size for output
  9872.               SO_RCVBUF          - set buffer size for input
  9873.               SO_TYPE            - get the type  of the  socket  (get
  9874.                                    only)
  9875.               SO_ERROR           - get and clear error on  the  socket
  9876.                                    (get  only)
  9877.  
  9878.  
  9879.          SO_DEBUG enables  debugging  in  the  underlying   protocol
  9880.          modules.   SO_REUSEADDR  indicates  that  the  rules used in
  9881.          validating addresses supplied in a bind() call should allow
  9882.          reuse oflocal addresses.  SO_KEEPALIVE enables the periodic
  9883.          transmission of messages on a connected socket.  Should  the
  9884.          connected  party fail to respond to these messages, the con-
  9885.          nection is considered broken. If  the  process  is
  9886.          waiting in select() when the connection is broken, select()
  9887.          returns true for any read or write events selected  for  the
  9888.          socket.    SO_DONTROUTE  indicates  that  outgoing  messages
  9889.          should bypass the  standard  routing  facilities.   Instead,
  9890.          messages are  directed to the appropriate network interface
  9891.          accordingto the network portion of the destination address.
  9892.  
  9893.  
  9894.          SO_LINGERcontrols the action taken when unsent messags  are
  9895.          queued  on  socket and a CloseSocket() is performed.  If the
  9896.          socket promises reliable delivery of data and  SO_LINGER  is
  9897.          set,  the system  will  block  the  process  on the close
  9898.          attempt until it is able to transmit the data  or  until  it
  9899.          decides it  is unable to deliver the information (a timeout
  9900.          period, in seconds, termed the linger interval, is specified
  9901.          in the set- sockopt() call when SO_LINGER is requested).  If
  9902.          SO_LINGER is  disabled and a CloseSocket()  is  issued, the
  9903.  
  9904.  
  9905. System Manual                  AmiTCP/IP                 Section B.1    141
  9906.  
  9907.  
  9908.  
  9909.          system will process the  close  in  a manner that allows the
  9910.          process to continue as quickly as possible.
  9911.  
  9912.  
  9913.          The option SO_BROADCAST requests permission to  send  broad-
  9914.          cast  datagrams  on  the socket.  Broadcast was a privileged
  9915.          operationin earlier versions of the system.  With protocols
  9916.          that  support  out-of-band  data,  the  SO_OOBINLINE  option
  9917.          requeststhat out-of-band data be placed in the normal  data
  9918.          input  queue  as  received;  it will then be accessible with
  9919.          recv() orread() calls without the MSG_OOB flag.   SO_SNDBUF
  9920.          and  SO_RCVBUF are options to adjust the normal buffer sizes
  9921.          allocatedfor output and input buffers,  respectively.   The
  9922.          buffer size may be increased for high-volume connections, or
  9923.          may be decreased to limit the possible backlog  of  incoming
  9924.          data.   The system places an absolute limit on these values.
  9925.          Finally,SO_TYPE and SO_ERROR are  options  used  only  with
  9926.          getsockopt().    SO_TYPE returns the type of the socket, such
  9927.          as SOCK_STREAM; it is useful for servers that inherit  sock-
  9928.          ets  on startup.  SO_ERROR returns any pending error on the
  9929.          socket and clears the error status.  It may be used to check
  9930.          for asynchronous errors on connected datagram sockets or for
  9931.          other asynchronous errors.
  9932.  
  9933.  
  9934.    RETURN VALUES
  9935.           0 - on success.
  9936.  
  9937.  
  9938.          -1 - on failure and set errno to indicate the error.
  9939.  
  9940.  
  9941.    ERRORS
  9942.          EBADF              -s is not a valid descriptor.
  9943.  
  9944.  
  9945.          ENOPROTOOPT        - The option is unknown at the level indi-
  9946.                               cated.
  9947.  
  9948.  
  9949.    SEE ALSO
  9950.          IoctlSocket(), socket()
  9951.  
  9952.  
  9953.    BUGS
  9954.          Several of the socket options should  be  handled  at  lower
  9955.          levels ofthe system.
  9956.  
  9957.  
  9958. 142    Section B.1                 AmiTCP/IP                  System Manual
  9959.  
  9960.  
  9961.  
  9962. B.1.9   IoctlSocket()
  9963.  
  9964.  
  9965.  
  9966.    NAME
  9967.          IoctlSocket - control sockets
  9968.  
  9969.  
  9970.    SYNOPSIS
  9971.  
  9972.  
  9973.          #include <sys/types.h>
  9974.          #include <sys/ioctl.h>
  9975.  
  9976.  
  9977.          value = IoctlSocket(fd, request, arg)
  9978.          D0            D0   D1       A0
  9979.  
  9980.  
  9981.          long IoctlSocket(long, long, caddr_t);
  9982.  
  9983.  
  9984.    FUNCTION
  9985.          IoctlSocket() performs a special function on the object referred
  9986.          to by theopen   socketdescriptor fd. Note: the setsockopt()
  9987.          call (seegetsockopt()) is the primary  method for operating
  9988.          on sockets  as such, rather than on the underlying  protocol
  9989.          or network interface.
  9990.  
  9991.  
  9992.          For mostIoctlSocket() functions, arg is a pointer to data to
  9993.          be used by the  function  or to be filled in by the function.
  9994.          Other functions may ignore arg or may treat it directly as a
  9995.          data item; they may, for example, be passed an int value.
  9996.  
  9997.  
  9998.          The following requests are supported:
  9999.  
  10000.  
  10001.  
  10002.          FIOASYNC            The argument is a  pointer  to  a  long.
  10003.                               Set  or  clear asynchronous I/O.  If the
  10004.                               value of that  long is  a  1  (one)  the
  10005.                               descriptor  is set for asynchronous I/O.
  10006.                               If the value of that long is a  0 (zero)
  10007.                               the  descriptor is cleared for asynchro-
  10008.                               nous I/O.
  10009.  
  10010.  
  10011.          FIOCLEX
  10012.          FIONCLEX            Ignored, no use for close-on-exec flag
  10013.                               in Amiga.
  10014.  
  10015.  
  10016.          FIOGETOWN
  10017.          SIOCGPGRP           The argument is pointer to struct Task*.
  10018.                               Set the value of that pointer to the
  10019.                               Task that  is  receiving SIGIO or SIGURG
  10020.                               signals for  the  socket  referred to by
  10021.                               the descriptor passed to IoctlSocket().
  10022.  
  10023.  
  10024.          FIONBIO             The argument is a  pointer  to  a  long.
  10025.                               Set  or  clear non-blocking I/O.  If the
  10026.  
  10027.  
  10028. System Manual                  AmiTCP/IP                 Section B.1    143
  10029.  
  10030.  
  10031.  
  10032.                               value of that  long is  a  1  (one)  the
  10033.                               descriptor  is set for non-blocking I/O.
  10034.                               If the value of that long is a  0 (zero)
  10035.                               the   descriptor  is  cleared  for  non-
  10036.                               blocking I/O.
  10037.  
  10038.  
  10039.          FIONREAD            The argument is a  pointer  to  a  long.
  10040.                               Set the value of that long to the number
  10041.                               of immediately readable characters  from
  10042.                               the socket fd.
  10043.  
  10044.  
  10045.          FIOSETOWN
  10046.          SIOCSPGRP           The argument is pointer to struct Task*,
  10047.                               pointer  to  the task  that will subseq-
  10048.                               uently receive  SIGIO or  SIGURG signals
  10049.                               for   the  socket  referred  to  by  the
  10050.                               descriptor passed.
  10051.  
  10052.  
  10053.          SIOCCATMARK          The argument is a pointer to a long.
  10054.                               Set the value of that long to 1 if the
  10055.                               read pointer for the socket referred to
  10056.                               by the descriptor passed to
  10057.                               IoctlSocket() points to a mark in the
  10058.                               data stream for an out-of-band message,
  10059.                               and to 0 if it does not point to a mark.
  10060.  
  10061.  
  10062.  
  10063.    RETURN VALUES
  10064.          IoctlSocket() returns 0 on success for most requests.   Some
  10065.          specialized requests may return non-zero values on success; On
  10066.          failure,  IoctlSocket()returns -1 and sets errno to indicate
  10067.          the error.
  10068.  
  10069.  
  10070.    ERRORS
  10071.          EBADF          fd is not a valid descriptor.
  10072.  
  10073.  
  10074.          EINVAL         request or arg is not valid.
  10075.  
  10076.  
  10077.          IoctlSocket() will also fail if the object on which the function
  10078.          is  being performed detects an error. In this case, an error
  10079.          code specific  to  the  object  and  the  function  will  be
  10080.          returned.
  10081.  
  10082.  
  10083.    SEE ALSO
  10084.          getsockopt(), SetSocketSignals(), setsockopt()
  10085.  
  10086.  
  10087. 144    Section B.1                 AmiTCP/IP                  System Manual
  10088.  
  10089.  
  10090.  
  10091. B.1.10   listen()
  10092.  
  10093.    NAME
  10094.          listen -listen for connections on a socket
  10095.  
  10096.  
  10097.    SYNOPSIS
  10098.          success =listen(s, backlog)
  10099.          D0                D0 D1
  10100.  
  10101.  
  10102.          long listen(long, long);
  10103.  
  10104.  
  10105.    FUNCTION
  10106.          To accept  connections,  a  socket  is  first  created  with
  10107.          socket(), a  backlog for incoming connections is specified
  10108.          with listen() and then the  connections  are  accepted  with
  10109.          accept().   The  listen()  call  applies only to socket of
  10110.          type SOCK_STREAM.
  10111.  
  10112.  
  10113.          The backlog parameter defines the maximum length  the  queue
  10114.          of pending connections may grow to.  If a connection request
  10115.          arrives with the queue full the client will receive an error
  10116.          with an indication of ECONNREFUSED.
  10117.  
  10118.  
  10119.    RETURN VALUES
  10120.           0    on success.
  10121.  
  10122.  
  10123.          -1    on failure and sets errno to indicate the error.
  10124.  
  10125.  
  10126.    ERRORS
  10127.          EBADF              -s is not a valid descriptor.
  10128.  
  10129.  
  10130.          EOPNOTSUPP         - The socketis not of a  type  that  sup-
  10131.                               ports listen().
  10132.  
  10133.  
  10134.    SEE ALSO
  10135.          accept(),connect(), socket()
  10136.  
  10137.  
  10138.    BUGS
  10139.          The backlog is currently limited (silently) to 5.
  10140.  
  10141.  
  10142. System Manual                  AmiTCP/IP                 Section B.1    145
  10143.  
  10144.  
  10145.  
  10146. B.1.11   recv()
  10147.  
  10148.  
  10149.  
  10150.    NAME
  10151.          recv, recvfrom, - receive a message from a socket
  10152.  
  10153.  
  10154.    SYNOPSIS
  10155.          #include <sys/types.h>
  10156.          #include <sys/socket.h>
  10157.  
  10158.  
  10159.         nbytes = recv(s, buf, len, flags)
  10160.         D0            D0 A0    D1    D2
  10161.  
  10162.  
  10163.         long recv(long, char *, long, long);
  10164.  
  10165.  
  10166.         nbytes = recvfrom(s, buf, len, flags, from, fromlen)
  10167.         D0                 D0 A0    D1    D2     A1    A2
  10168.  
  10169.  
  10170.         long recvfrom(long, char *, long, long,
  10171.                           struct sockaddr *, long *);
  10172.  
  10173.  
  10174.    FUNCTION
  10175.          s is a socket created with socket().  recv() and recvfrom(),
  10176.          are used to  receive messages from  another socket.  recv()
  10177.          may  be used  only on a connected socket  (see  connect()),
  10178.          while  recvfrom() may be used  to receive data  on a  socket
  10179.          whether it is in a connected state or not.
  10180.  
  10181.  
  10182.          If from is not a NULL pointer, the  source  address  of  the
  10183.          message is filled in.  fromlen is a value-result parameter,
  10184.          initialized to the size of the buffer associated with  from,
  10185.          and  modified  on  return to indicate the actual size of the
  10186.          address stored  there.    The  length  of  the  message    is
  10187.          returned.   If  a message is too long to fitin the supplied
  10188.          buffer, excess bytes may be discarded depending on the  type
  10189.          of socketthe message is received from (see socket()).
  10190.  
  10191.  
  10192.          If no messages are available at the socket, the receive call
  10193.          waits  for  a  message  to arrive, unless the socket is non-
  10194.          blocking(see IoctlSocket()) in which case -1  is  returned
  10195.          with theexternal variable errno set to EWOULDBLOCK.
  10196.  
  10197.  
  10198.          The select() call may be used to determine when  more  data
  10199.          arrive.
  10200.  
  10201.  
  10202.          The flagsparameter is formed by ORing one or  more  of  the
  10203.          following:
  10204.  
  10205.  
  10206.          MSG_OOB      - Read any "out-of-band" data  present on  the
  10207.                          socket,  rather  than  the  regular "in-band"
  10208.                          data.
  10209.  
  10210.  
  10211. 146    Section B.1                 AmiTCP/IP                  System Manual
  10212.  
  10213.  
  10214.  
  10215.          MSG_PEEK     - "Peek" at the data present onthe socket; the
  10216.                          data  are returned, but not consumed, so that
  10217.                          a subsequent receive operation will  see  the
  10218.                          same data.
  10219.  
  10220.  
  10221.    RETURN VALUES
  10222.          These calls return the number of bytes received, or -1 if an
  10223.          error occurred.
  10224.  
  10225.  
  10226.    ERRORS
  10227.          EBADF              -s is an invalid descriptor.
  10228.  
  10229.  
  10230.          EINTR              -The operation was interrupted by a break
  10231.                               signal.
  10232.  
  10233.  
  10234.          EWOULDBLOCK        - The socket is  marked  non-blocking and
  10235.                               the requested operation would block.
  10236.  
  10237.  
  10238.    SEE ALSO
  10239.          connect(), getsockopt(), IoctlSocket(), select(), send(),
  10240.          SetSocketSignals(), socket()
  10241.  
  10242.  
  10243. System Manual                  AmiTCP/IP                 Section B.1    147
  10244.  
  10245.  
  10246.  
  10247. B.1.12   select()
  10248.  
  10249.  
  10250.  
  10251.    NAME
  10252.          select --synchronous I/O multiplexing (stub/inline function)
  10253.          WaitSelect -- select() with Amiga Wait() function.
  10254.  
  10255.  
  10256.    SYNOPSIS
  10257.          #include <sys/types.h>
  10258.          #include <sys/time.h>
  10259.  
  10260.  
  10261.          n = select (nfds, readfds, writefds, exceptfds, timeout)
  10262.  
  10263.  
  10264.          long select(long, fd_set *, fd_set *, fd_set *,
  10265.                       struct timeval *);
  10266.  
  10267.  
  10268.          n = WaitSelect (nfds, readfds, writefds, exceptfds, timeout,
  10269.          D0               D0    A0        A1         A2         A3
  10270.                       sigmp)
  10271.                       D1
  10272.  
  10273.  
  10274.          long WaitSelect(long, fd_set *, fd_set *, fd_set *,
  10275.                           struct timeval *, long *);
  10276.  
  10277.  
  10278.          FD_SET (fd, &fdset)
  10279.          FD_CLR (fd, &fdset)
  10280.          FD_ISSET(fd, &fdset)
  10281.          FD_ZERO (&fdset)
  10282.          long fd;
  10283.          fd_set fdset;
  10284.  
  10285.  
  10286.    DESCRIPTION
  10287.          select()examines the socket descriptor sets whose addresses
  10288.          are passed in readfds,  writefds,  and exceptfds  to  see if
  10289.          some of their descriptors are ready  for reading,  ready for
  10290.          writing, or have an exceptional condition pending.  nfds is
  10291.          the  number  of bits to be checked in  each  bit  mask  that
  10292.          representa file descriptor; the descriptors from 0  through
  10293.          (nfds - 1) in the descriptor sets  are examined.  On return,
  10294.          select() replaces  the  given descriptor sets  with subsets
  10295.          consisting of  those descriptors  that  are  ready  for  the
  10296.          requestedoperation.  The total number  of ready descriptors
  10297.          in all the sets is returned.
  10298.  
  10299.  
  10300.          WaitSelect() also takes a signal mask which is waited during
  10301.          normal select() operation. If one of these singals is recei-
  10302.          ved,  WaitSelect() returns  and has  re-set  the signal mask
  10303.          to returnthose signals that  have arrived.  Normal select()
  10304.          return values are returned.
  10305.  
  10306.  
  10307.          The descriptor sets are stored as bit fields  in  arrays  of
  10308.          integers.   The following macros are provided for manipulat-
  10309.  
  10310.  
  10311. 148    Section B.1                 AmiTCP/IP                  System Manual
  10312.  
  10313.  
  10314.  
  10315.          ing suchdescriptor sets:  FD_ZERO  (&fdset)  initializes  a
  10316.          descriptor  set  fdset to the null set.  FD_SET(fd, &fdset )
  10317.          includesa particular descriptor fd  in  fdset.   FD_CLR(fd,
  10318.          &fdset) removes  fd  from  fdset.   FD_ISSET(fd, &fdset) is
  10319.          nonzero if fd is a member of  fdset,  zero  otherwise.   The
  10320.          behavior  of these macros is undefined if a descriptor value
  10321.          is less than zero or greater than or  equal  to  FD_SETSIZE,
  10322.          which  is normally  at least equal to the maximum number of
  10323.          descriptors supported by the system.
  10324.  
  10325.  
  10326.          If timeout is not a NULL pointer,  it  specifies  a  maximum
  10327.          interval to wait for the selection to complete.  If timeout
  10328.          is a NULL pointer,  the  select  blocks  indefinitely.   To
  10329.          effect  a poll,  the  timeout argument should be a non-NULL
  10330.          pointer,pointing to a zero-valued timeval structure.
  10331.  
  10332.  
  10333.          Any of readfds, writefds, and exceptfds may be given as NULL
  10334.          pointersif no descriptors are of interest.
  10335.  
  10336.  
  10337.          Selectingtrue for reading on a socket descriptor upon which
  10338.          a  listen() call has been performed indicates that a subse-
  10339.          quent accept() call on that descriptor will not block.
  10340.  
  10341.  
  10342.    RETURN VALUES
  10343.          select()returns a non-negative value on success. A positive
  10344.          value indicates the number of ready descriptors in the
  10345.          descriptor sets. 0 indicates that the time limit referred to
  10346.          by timeout expired or that the operation was interrupted
  10347.          either bya break signal or by arrival of a signal specified
  10348.          in *sigmp. On failure, select() returns -1, sets errno to
  10349.          indicatethe error, and the descriptor sets are not changed.
  10350.  
  10351.  
  10352.    ERRORS
  10353.          EBADF         - One  of  the  descriptor  sets  specified  an
  10354.                          invalid descriptor.
  10355.  
  10356.  
  10357.          EINTR         - one of the signals in SIGINTR  mask (see Set-
  10358.                          SocketSignals())   is  set  and  it  was not
  10359.                          requested in WaitSelect() call.
  10360.  
  10361.  
  10362.          EINVAL       - A component of the pointed-to time  limit is
  10363.                          outside  the  acceptable range: t_sec must be
  10364.                          between 0 and 10^8,inclusive. t_usec must be
  10365.                          greater  than  or equal  to 0, and less than
  10366.                          10^6.
  10367.  
  10368.  
  10369.    SEE ALSO
  10370.          accept(),  connect(), getdtablesize(), listen(), recv(),
  10371.          send(), SetDTableSize(), SetSocketSignals()
  10372.  
  10373.  
  10374.    NOTES
  10375.  
  10376.  
  10377. System Manual                  AmiTCP/IP                 Section B.1    149
  10378.  
  10379.  
  10380.  
  10381.          Under rare  circumstances,  select()  may  indicate  that  a
  10382.          descriptor  is  ready for writing when in fact an attempt to
  10383.          write would block.  This  can  happen  if  system  resources
  10384.          necessary for  a  write are exhausted or otherwise unavail-
  10385.          able.  Ifan application deems it critical that writes to  a
  10386.          file  descriptor not block, it should set the descriptor for
  10387.          non-blocking I/O using the FIOASYNC request to IoctlSocket().
  10388.  
  10389.  
  10390.          Default   system    limit  for  open  socket  descriptors  is
  10391.          currently 64. However,  in  order  to accommodate  programs
  10392.          which might  potentially  use  a larger number of open files
  10393.          with select, it is possible  to  increase this size within a
  10394.          program by  providing  a  larger definition  of  FD_SETSIZE
  10395.          before    the    inclusion     of    <sys/types.h>     and    use
  10396.          SetDTableSize(FD_SETSIZE) call directly after OpenLibrary().
  10397.  
  10398.  
  10399.    BUGS
  10400.          select()should probably return the time remaining from  the
  10401.          original timeout,  if  any,  by modifying the time value in
  10402.          place.  This may be implemented in future  versions  of  the
  10403.          system.   Thus,  it  is  unwise  to  assume that the timeout
  10404.          pointer will be unmodified by the select() call.
  10405.  
  10406.  
  10407. 150    Section B.1                 AmiTCP/IP                  System Manual
  10408.  
  10409.  
  10410.  
  10411. B.1.13   send()
  10412.  
  10413.  
  10414.  
  10415.    NAME
  10416.          send, sendto - send a message from a socket
  10417.  
  10418.  
  10419.    SYNOPSIS
  10420.          #include <sys/types.h>
  10421.          #include <sys/socket.h>
  10422.  
  10423.  
  10424.          nbytes =send(s, msg, len, flags)
  10425.          D0            D0  A0   D1    D2
  10426.  
  10427.  
  10428.          int send(int, char *, int, int);
  10429.  
  10430.  
  10431.          nbytes =sendto(s, msg, len, flags, to, tolen)
  10432.          D0               D0 A0    D1    D2     A1  D3
  10433.  
  10434.  
  10435.          int send(int, char *, int, int, struct sockaddr *, int);
  10436.  
  10437.  
  10438.    FUNCTION
  10439.          s is a socket created with socket().  send() and sendto() are
  10440.          used  totransmit a message to  another socket. send() may be
  10441.          used  only when the socket  is  in a connected  state,  while
  10442.          sendto()may be used at any time.
  10443.  
  10444.  
  10445.          The address of the target  is given by to with tolen specify-
  10446.          ing its size.  The length of the message is given by len.  If
  10447.          the  message is  too  long  to  pass  atomically  through the
  10448.          underlying protocol, then the error EMSGSIZE is returned, and
  10449.          the message is not transmitted.
  10450.  
  10451.  
  10452.          No indication of failure to deliver is implicit  in a send().
  10453.          Return values of -1 indicate some locally detected errors.
  10454.  
  10455.  
  10456.          If no buffer space is  available at the socket  to  hold  the
  10457.          message to  be  transmitted,  then  send() normally  blocks,
  10458.          unless the  socket  has been placed in non-blocking I/O mode.
  10459.          The select() call may be used to determine when  it  is  pos-
  10460.          sible tosend more data.
  10461.  
  10462.  
  10463.          The flagsparameter is formed  by ORing  one  or  more of the
  10464.          following:
  10465.  
  10466.  
  10467.          MSG_OOB           - Send  ``out-of-band''  data  on  sockets
  10468.                               that  support this notion.  The underly-
  10469.                               ing protocol must  also  support  ``out-
  10470.                               of-band''    data.      Currently,   only
  10471.                               SOCK_STREAM  sockets  created    in    the
  10472.                               AF_INET  address  family support out-of-
  10473.                               band data.
  10474.  
  10475.  
  10476. System Manual                  AmiTCP/IP                 Section B.1    151
  10477.  
  10478.  
  10479.  
  10480.          MSG_DONTROUTE      - The SO_DONTROUTE optionis turned on for
  10481.                               the  duration of the operation.  This is
  10482.                               usually used only by diagnostic or rout-
  10483.                               ing programs.
  10484.  
  10485.  
  10486.    RETURN VALUES
  10487.          On success, these functions return the number of bytes sent.
  10488.          On  failure,  they  return  -1 and set errno to indicate the
  10489.          error.
  10490.  
  10491.  
  10492.    ERRORS
  10493.          EBADF              -s is an invalid descriptor.
  10494.  
  10495.  
  10496.          EINTR              -The operation was interrupted by a break
  10497.                                signal.
  10498.  
  10499.  
  10500.          EINVAL            - len is not the size of a  valid  address
  10501.                               for the specified address family.
  10502.  
  10503.  
  10504.          EMSGSIZE          - The socket requires that message be sent
  10505.                               atomically,  and the size of the message
  10506.                               to be sent made this impossible.
  10507.  
  10508.  
  10509.          ENOBUFS           - The system was  unable  to  allocate  an
  10510.                               internal    buffer.    The  operation  may
  10511.                               succeed when buffers become available.
  10512.  
  10513.  
  10514.          ENOBUFS           - The output queue for a network interface
  10515.                               was full.  This generally indicates that
  10516.                               the interface has stopped  sending,  but
  10517.                               may be caused by transient congestion.
  10518.  
  10519.  
  10520.          EWOULDBLOCK        - The socket is  marked  non-blocking and
  10521.                               the requested operation would block.
  10522.  
  10523.  
  10524.    SEE ALSO
  10525.          connect(), getsockopt(), recv(), select(), socket()
  10526.  
  10527.  
  10528. 152    Section B.1                 AmiTCP/IP                  System Manual
  10529.  
  10530.  
  10531.  
  10532. B.1.14   shutdown()
  10533.  
  10534.    NAME
  10535.          shutdown- shut down part of a full-duplex connection
  10536.  
  10537.  
  10538.    SYNOPSIS
  10539.          success =shutdown(s, how)
  10540.          D0                  D0 D1
  10541.  
  10542.  
  10543.          long shutdown(long, long);
  10544.  
  10545.  
  10546.    DESCRIPTION
  10547.          The shutdown() call causes all or part of a full-duplex con-
  10548.          nection on the socket associated with s to be shut down.  If
  10549.          how is 0,then further receives will be disallowed.  If  how
  10550.          is  1,  then further sends will be disallowed.  If how is 2,
  10551.          then further sends and receives will be disallowed.
  10552.  
  10553.  
  10554.    RETURN VALUES
  10555.           0 - on success.
  10556.  
  10557.  
  10558.          -1 - on failure and sets errno to indicate the error.
  10559.  
  10560.  
  10561.    ERRORS
  10562.          EBADF         - s is not a valid descriptor.
  10563.  
  10564.  
  10565.          ENOTCONN     - The specified socket is not connected.
  10566.  
  10567.  
  10568.    SEE ALSO
  10569.          connect(),  socket()
  10570.  
  10571.  
  10572.    BUGS
  10573.          The how values should be defined constants.
  10574.  
  10575.  
  10576. System Manual                  AmiTCP/IP                 Section B.1    153
  10577.  
  10578.  
  10579.  
  10580. B.1.15   socket()
  10581.  
  10582.  
  10583.  
  10584.    NAME
  10585.          socket -create an endpoint for communication
  10586.  
  10587.  
  10588.    SYNOPSIS
  10589.          #include <sys/types.h>
  10590.          #include <sys/socket.h>
  10591.  
  10592.  
  10593.          s = socket(domain, type, protocol)
  10594.          D0          D0      D1    D2
  10595.  
  10596.  
  10597.          long socket(long, long, long);
  10598.  
  10599.  
  10600.    FUNCTION
  10601.          socket()creates an endpoint for communication and returns a
  10602.          descriptor.
  10603.  
  10604.  
  10605.          The  domain  parameter  specifies  a  communications  domain
  10606.          within which communication will take place; this selects the
  10607.          protocol family  which should be used.  The protocol family
  10608.          generally is  the  same  as  the  address  family  for  the
  10609.          addressessupplied in later operations on the socket.  These
  10610.          families are defined  in the  include file  <sys/socket.h>.
  10611.          The currently understood formats are
  10612.  
  10613.  
  10614.                  PF_INET - (ARPA Internet protocols)
  10615.  
  10616.  
  10617.          The socket has the indicated type, which specifies the
  10618.          semanticsof communication.  Currently defined types are:
  10619.  
  10620.  
  10621.                  SOCK_STREAM
  10622.                  SOCK_DGRAM
  10623.                  SOCK_RAW
  10624.  
  10625.  
  10626.          A  SOCK_STREAM type  provides  sequenced,  reliable, two-way
  10627.          connection  based    byte  streams.    An    out-of-band  data
  10628.          transmission  mechanism  may  be  supported.   A  SOCK_DGRAM
  10629.          socket supports datagrams  (connectionless, unreliable  mes-
  10630.          sages  of a  fixed    (typically    small)  maximum  length).
  10631.          SOCK_RAW   sockets    provide  access  to   internal  network
  10632.          interfaces.
  10633.  
  10634.  
  10635.          The protocol specifies a particular protocol to be used with
  10636.          the socket.  Normally  only a single protocol exists to sup-
  10637.          port a particular socket type  within a given  protocol fam-
  10638.          ily.  However, it is possible that many protocols may exist,
  10639.          in whichcase a  particular protocol  must be  specified  in
  10640.          this manner.  The  protocol number to use  is  particular to
  10641.          the "communication domain" in which communication is to take
  10642.          place.
  10643.  
  10644.  
  10645. 154    Section B.1                 AmiTCP/IP                  System Manual
  10646.  
  10647.  
  10648.  
  10649.          Sockets of type SOCK_STREAM  are  full-duplex byte  streams,
  10650.          similar to pipes.    A  streamsocket must be in  a connected
  10651.          state before any data may be sent or received on it.  A con-
  10652.          nection  to another socket is created with a connect() call.
  10653.          Once  connected, data  may be  transferred using send()  and
  10654.          recv()  or their variant calls.   When  a  session  has been
  10655.          completeda CloseSocket()  may  be  performed.   Out-of-band
  10656.          data mayalso  be transmitted  as  described  in  send() and
  10657.          receivedas described in recv().
  10658.  
  10659.  
  10660.          The communications protocols used to implement a SOCK_STREAM
  10661.          insure that data is  not lost or  duplicated.  If a piece of
  10662.          data for  which the peer protocol has buffer space cannot be
  10663.          successfully transmitted within a reasonable length of time,
  10664.          then the connection  is  considered broken  and  calls will
  10665.          indicatean error with -1 returns and with ETIMEDOUT  as the
  10666.          specificerror code (see Errno()).  The protocols optionally
  10667.          keep sockets "warm" by  forcing transmissions roughly  every
  10668.          minute inthe absence of other activity.
  10669.  
  10670.  
  10671.          SOCK_DGRAM  and SOCK_RAW sockets allow sending of  datagrams
  10672.          to  correspondents  named in send()  calls.   Datagrams  are
  10673.          generally received  with  recv(), which  returns  the  next
  10674.          datagramwith its return address.
  10675.  
  10676.  
  10677.          The operation of  sockets  is  controlled  by  socket  level
  10678.          options.   These  options  aredefined in the file socket.h.
  10679.          getsockopt()  and  setsockopt()  are  used  to  get  and  set
  10680.          options, respectively.
  10681.  
  10682.  
  10683.    RETURN VALUES
  10684.          socket()returns a non-negative descriptor on  success.   On
  10685.          failure,it returns -1 and sets errno to indicate the error.
  10686.  
  10687.  
  10688.    ERRORS
  10689.          EACCES          - Permission to create  a  socket  of  the
  10690.                             specified    type    and/or    protocol   is
  10691.                             denied.
  10692.  
  10693.  
  10694.          EMFILE          - The per-process descriptor table is
  10695.                             full.
  10696.  
  10697.  
  10698.          ENOBUFS         - Insufficient buffer space is available.
  10699.                             The socket cannot be created until suf-
  10700.                             ficient resources are freed.
  10701.  
  10702.  
  10703.          EPROTONOSUPPORT - The protocol type or the specified  pro-
  10704.                             tocol is not supported within this
  10705.                             domain.
  10706.  
  10707.  
  10708. System Manual                  AmiTCP/IP                 Section B.1    155
  10709.  
  10710.  
  10711.  
  10712.          EPROTOTYPE       - The protocol is the wrong type for the
  10713.                             socket.
  10714.  
  10715.  
  10716.    SEE ALSO
  10717.          accept(),bind(), CloseSocket(), connect(), getsockname(),
  10718.          getsockopt(), IoctlSocket(), listen(), recv(), select(),
  10719.          send(), shutdown(), WaitSelect()
  10720.  
  10721.  
  10722. 156    Section B.2                 AmiTCP/IP                  System Manual
  10723.  
  10724.  
  10725.  
  10726. B.2     Other  BSD  Functions  Related  to  Sockets
  10727.  
  10728.  
  10729. B.2.1   getdtablesize()
  10730.  
  10731.    NAME
  10732.          getdtablesize - get socket descriptor table size
  10733.  
  10734.  
  10735.    SYNOPSIS
  10736.  
  10737.  
  10738.          nfds = getdtablesize()
  10739.          D0
  10740.  
  10741.  
  10742.          long getdtablesize(void);
  10743.  
  10744.  
  10745.    FUNCTION
  10746.          Return value of maximum  number of open socket  descriptors.
  10747.          Larger  socket  descriptor  table  can   be  allocated  with
  10748.          SetDTableSize() call.
  10749.  
  10750.  
  10751.    SEE ALSO
  10752.          SetDTableSize()
  10753.  
  10754.  
  10755. System Manual                  AmiTCP/IP                 Section B.2    157
  10756.  
  10757.  
  10758.  
  10759. B.2.2   Syslog()
  10760.  
  10761.  
  10762.  
  10763.    NAME
  10764.          syslog -write message to AmiTCP/IP log.
  10765.  
  10766.  
  10767.    SYNOPSIS
  10768.          #include <syslog.h>
  10769.  
  10770.  
  10771.          void syslog(unsigned long level, char * format, ...);
  10772.  
  10773.  
  10774.          Syslog(level, format, ap)
  10775.                D0     A0       A1
  10776.  
  10777.  
  10778.          VOID Syslog(unsigned long, const char *, va_list);
  10779.  
  10780.  
  10781.  
  10782.    FUNCTION
  10783.          Writes the message given as format string and arguments
  10784.          (printf-style) both to the log file and to the console,
  10785.          execpt ifthe level is LOG_EMERG, which is used by panic(),
  10786.          in whichcase only the log file is used since panic()
  10787.          generatesa User Request.
  10788.  
  10789.  
  10790.          The levelis selected from an ordered list:
  10791.  
  10792.  
  10793.               LOG_EMERG            A panic condition.
  10794.  
  10795.  
  10796.               LOG_ALERT            A condition thatshould be
  10797.                                    corrected immediately, such as a
  10798.                                    corrupted system database.
  10799.  
  10800.  
  10801.               LOG_CRIT             Critical conditions, such  as  hard
  10802.                                    device errors.
  10803.  
  10804.  
  10805.               LOG_ERR              Errors.
  10806.  
  10807.  
  10808.               LOG_WARNING          Warning messages.
  10809.  
  10810.  
  10811.               LOG_NOTICE           Conditions that are not error  con-
  10812.                                    ditions,   butthat may require spe-
  10813.                                    cial  handling.
  10814.  
  10815.  
  10816.               LOG_INFO             Informational messages.
  10817.  
  10818.  
  10819.               LOG_DEBUG            Messages that  contain information
  10820.                                    normally of use only when debugging
  10821.                                    a  program.
  10822.  
  10823.  
  10824.    INPUTS
  10825.          Level     - indicates the type of the message. The levels
  10826.                       are defined in sys/syslog.h and listed above.
  10827.  
  10828.  
  10829. 158    Section B.2                 AmiTCP/IP                  System Manual
  10830.  
  10831.  
  10832.  
  10833.          format    - This is a printf-style format string as defined
  10834.                       in  exec.library/RawDoFmt().
  10835.  
  10836.  
  10837.          arguments- as in printf().
  10838.  
  10839.  
  10840.          ap         - pointer to an array of arguments.
  10841.  
  10842.  
  10843.    RESULT
  10844.          Returns no value.
  10845.  
  10846.  
  10847.    EXAMPLES
  10848.          To  log a message at priority  LOG_INFO, it would  make the
  10849.          followingcall to syslog:
  10850.  
  10851.  
  10852.               syslog(LOG_INFO,  "Connection from host %s",
  10853.                       CallingHost);
  10854.  
  10855.  
  10856.    NOTES
  10857.          As Exec RawDoFmt() used to do formatting expects by default
  10858.          short (16bit long) integers you should use the `l'-modifier
  10859.          when appopriate. See your compiler documentation about how
  10860.          it passesarguments on a vararg list.
  10861.  
  10862.  
  10863.          This function is callable from interrupts.
  10864.  
  10865.  
  10866.    BUGS
  10867.          Because there is a limited number of internal messages used
  10868.          by the logging system, some log messages may get lost if a
  10869.          high priority task or interrupt handler sends many messages
  10870.          in succession. If this happens, the next log message tells
  10871.          the fact.
  10872.  
  10873.  
  10874.    SEE ALSO
  10875.         exec.library/RawDoFmt()
  10876.  
  10877.  
  10878. System Manual                  AmiTCP/IP                 Section B.3    159
  10879.  
  10880.  
  10881.  
  10882. B.3     Network  Data  and Address  Manipulation
  10883.  
  10884.  
  10885.  
  10886. B.3.1   inet _addr()
  10887.  
  10888.  
  10889.    NAME
  10890.          inet_addr,  inet_network,  Inet_MakeAddr,  Inet_LnaOf,
  10891.          Inet_NetOf, Inet_NtoA - Internet address manipulation
  10892.  
  10893.  
  10894.          inet_makeaddr, inet_lnaof, inet_netof,
  10895.          inet_ntoa-- inline/stub functions to handle structure arguments
  10896.  
  10897.  
  10898.    SYNOPSIS
  10899.          #include <netinet/in.h>
  10900.  
  10901.  
  10902.          addr = inet_addr(cp)
  10903.          D0                A0
  10904.  
  10905.  
  10906.          unsignedlong inet_addr(char *);
  10907.  
  10908.  
  10909.          net = inet_network(cp)
  10910.          D0                  A0
  10911.  
  10912.  
  10913.          unsignedlong inet_network(char *);
  10914.  
  10915.  
  10916.          in_addr =Inet_MakeAddr(net, lna)
  10917.          D0                       D0   D1
  10918.  
  10919.  
  10920.          unsignedlong Inet_MakeAddr(long, long);
  10921.  
  10922.  
  10923.          lna = Inet_LnaOf(in)
  10924.          D0                D0
  10925.  
  10926.  
  10927.          long Inet_LnaOf(unsigned long);
  10928.  
  10929.  
  10930.          net = Inet_NetOf(in)
  10931.          D0                D0
  10932.  
  10933.  
  10934.          long Inet_NetOf(unsigned long);
  10935.  
  10936.  
  10937.          addr = Inet_NtoA(in)
  10938.          DO                D0
  10939.  
  10940.  
  10941.          char * Inet_NtoA(unsigned long);
  10942.  
  10943.  
  10944.  
  10945.          in_addr =inet_makeaddr(net, lna)
  10946.  
  10947.  
  10948.          struct in_addr inet_makeaddr(long, long);
  10949.  
  10950.  
  10951.          lna = inet_lnaof(in)
  10952.  
  10953.  
  10954. 160    Section B.3                 AmiTCP/IP                  System Manual
  10955.  
  10956.  
  10957.  
  10958.          int inet_lnaof(struct in_addr);
  10959.  
  10960.  
  10961.          net = inet_netof(in)
  10962.  
  10963.  
  10964.          int inet_netof(struct in_addr);
  10965.  
  10966.  
  10967.          addr = inet_ntoa(in)
  10968.  
  10969.  
  10970.          char * inet_ntoa(struct in_addr);
  10971.  
  10972.  
  10973.    IMPLEMENTATION NOTE
  10974.          Return  value  of  Inet_MakeAddr()  and  argument  types  of
  10975.          Inet_LnaOf(), Inet_NetOf() and Inet_NtoA() are longs instead
  10976.          of  struct  in_addr.  The original behaviour  is achieved by
  10977.          using  included  stub  functions (lower case function names)
  10978.          which handle structure arguments.
  10979.  
  10980.  
  10981.    DESCRIPTION
  10982.          The routines inet_addr() and inet_network()  each  interpret
  10983.          character strings  representing  numbers  expressed  in the
  10984.          Internetstandard `.' notation, returning  numbers  suitable
  10985.          for  use as Internet addresses and Internet network numbers,
  10986.          respectively.   The routine inet_makeaddr() takes an Internet
  10987.          network number and a local network address and constructs an
  10988.          Internetaddress from it.    The  routines  inet_netof()  and
  10989.          inet_lnaof()   break apart Internet host addresses, returning
  10990.          the network number and local network address  part,  respec-
  10991.          tively.
  10992.  
  10993.  
  10994.          The routine inet_ntoa() returns a pointer to a string in the
  10995.          base 256notation ``d.d.d.d'' described below.
  10996.  
  10997.  
  10998.          All Internet address are returned in  network  order  (bytes
  10999.          ordered from left to right).  All network numbers and local
  11000.          address parts are returned as machine format integer values.
  11001.  
  11002.  
  11003.    INTERNET ADDRESSES
  11004.          Values specified using the `.'  notation  take  one  of  the
  11005.  
  11006.  
  11007.          following forms:
  11008.  
  11009.  
  11010.               a.b.c.d
  11011.               a.b.c
  11012.               a.b
  11013.               a
  11014.  
  11015.  
  11016.          When fourparts are specified, each is interpreted as a byte
  11017.          of data and assigned, from left to right, to  the four bytes
  11018.          of  an Internet address.  Note: when  an Internet address is
  11019.          viewed  as  a  32-bit  integer  quantity  on  little  endian
  11020.          systems, the  bytes referred to  above appear  as  d.c.b.a.
  11021.  
  11022.  
  11023. System Manual                  AmiTCP/IP                 Section B.3    161
  11024.  
  11025.  
  11026.  
  11027.          bytes areordered from right to left.
  11028.  
  11029.  
  11030.          When a three part address is specified,  the  last  part  is
  11031.          interpreted  as  a  16-bit  quantity and placed in the right
  11032.          most twobytes of the network address.  This makes the three
  11033.          part  address  format convenient for specifying Class B net-
  11034.          work addresses as "128.net.host".
  11035.  
  11036.  
  11037.          When a two part address is supplied, the last part is inter-
  11038.          preted  as  a  24-bit  quantity and placed in the right most
  11039.          three bytes of the network address.  This makes the two part
  11040.          address format  convenient  for  specifying Class A network
  11041.          addressesas "net.host".
  11042.  
  11043.  
  11044.          When onlyone part is given, the value is stored directly in
  11045.          the network address without any byte rearrangement.
  11046.  
  11047.  
  11048.          All numbers supplied as ``parts'' in a `.' notation  may  be
  11049.          decimal, octal,  or  hexadecimal,  as  specified  in  the C
  11050.          language(that is, a leading 0x or 0X  implies  hexadecimal;
  11051.          otherwise,   a leading0 implies octal; otherwise, the number
  11052.          is interpreted as decimal).
  11053.  
  11054.  
  11055.    RETURN VALUE
  11056.          The value-1 is returned by inet_addr()  and  inet_network()
  11057.          for malformed requests.
  11058.  
  11059.  
  11060.    BUGS
  11061.          The problem of host byte ordering versus network byte order-
  11062.          ing  is confusing.  A simple way to specify Class C network
  11063.          addressesin a manner similar to that for Class B and  Class
  11064.          A is needed.
  11065.  
  11066.  
  11067.          The return value from inet_ntoa() points to static buffer
  11068.          which  is overwritten  in  each inet_ntoa() call.
  11069.  
  11070.  
  11071. 162    Section B.4                 AmiTCP/IP                  System Manual
  11072.  
  11073.  
  11074.  
  11075. B.4     Network,  Protocol and  Service  Queries
  11076.  
  11077.  
  11078.  
  11079. B.4.1   gethostbyname()
  11080.  
  11081.  
  11082.    NAME
  11083.          gethostbyname, gethostbyaddr  - get network host entry
  11084.  
  11085.  
  11086.    SYNOPSIS
  11087.          #include <sys/types.h>
  11088.          #include <sys/socket.h>
  11089.          #include <netdb.h>
  11090.  
  11091.  
  11092.          hostent =gethostbyname(name)
  11093.          D0                       A0
  11094.  
  11095.  
  11096.          struct hostent *gethostbyname(char *);
  11097.  
  11098.  
  11099.          hostent =gethostbyaddr(addr, len, type)
  11100.          D0                       A0     D0   D1
  11101.  
  11102.  
  11103.          struct hostent *gethostbyaddr(caddr_t, LONG, LONG);
  11104.  
  11105.  
  11106.  
  11107.    DESCRIPTION
  11108.          gethostbyname() and gethostbyaddr() both return a pointer
  11109.          to an object with the following structure containing the
  11110.          data received from a name server or the broken-out fields
  11111.          of a linein netdb configuration file.  In the case of
  11112.          gethostbyaddr(), addr is a pointer to the binary format
  11113.          address of length len (not a character string) and type is
  11114.          an address family as defined in <sys/socket.h>.
  11115.  
  11116.  
  11117.            struct hostent -
  11118.              char *h_name;       /* official name of host */
  11119.              char **h_aliases;   /* alias list */
  11120.              int  h_addrtype;    /* address type */
  11121.              int  h_length;      /* length of address */
  11122.              char **h_addr_list; /* list of addresses from name server */
  11123.            ";
  11124.  
  11125.  
  11126.          The members of this structure are:
  11127.  
  11128.  
  11129.          h_name               Official name of the host.
  11130.  
  11131.  
  11132.          h_aliases           A zero  terminated  array  of  alternate
  11133.                               names for the host.
  11134.  
  11135.  
  11136.          h_addrtype           The  type  of  address  being  returned;
  11137.                               currently always AF_INET.
  11138.  
  11139.  
  11140.          h_length            The length, in bytes, of the address.
  11141.  
  11142.  
  11143. System Manual                  AmiTCP/IP                 Section B.4    163
  11144.  
  11145.  
  11146.  
  11147.          h_addr_list          A pointer to a list of network addresses
  11148.                               for  the named host.  Host addresses are
  11149.                               returned in network byte order.
  11150.  
  11151.  
  11152.    DIAGNOSTICS
  11153.          A NULL pointer is returned if no matching entry was found or
  11154.          error occured.
  11155.  
  11156.  
  11157.    BUGS
  11158.          All information is contained in a static area so it must  be
  11159.          copied ifit is to be saved.  Only the Internet address for-
  11160.          mat is currently understood.
  11161.  
  11162.  
  11163.    SEE ALSO
  11164.          AmiTCP/IP configuration
  11165.  
  11166.  
  11167. 164    Section B.4                 AmiTCP/IP                  System Manual
  11168.  
  11169.  
  11170.  
  11171. B.4.2   getnetbyname()
  11172.  
  11173.  
  11174.  
  11175.    NAME
  11176.          getnetbyname, getnetbyaddr - get network entry
  11177.  
  11178.  
  11179.    SYNOPSIS
  11180.          #include <netdb.h>
  11181.  
  11182.  
  11183.          netent =getnetbyname(name)
  11184.          D0                     A0
  11185.  
  11186.  
  11187.          struct netent *getnetbyname(char *);
  11188.  
  11189.  
  11190.          netent =getnetbyaddr(net, type)
  11191.          D0                     D0   D1
  11192.  
  11193.  
  11194.          struct netent *getnetbyaddr(long, long);
  11195.  
  11196.  
  11197.    DESCRIPTION
  11198.          getnetbyname(), and getnetbyaddr() both return  a  pointer to
  11199.          an  object  with  the  following  structure  containing   the
  11200.          broken-out fields of a line in netdb configuration file.
  11201.  
  11202.  
  11203.            struct netent -
  11204.              char *n_name;       /* official name of net */
  11205.              char **n_aliases;   /* alias list */
  11206.              int  n_addrtype;    /* net number type */
  11207.              long n_net;         /* net number */
  11208.            ";
  11209.  
  11210.  
  11211.          The members of this structure are:
  11212.  
  11213.  
  11214.          n_name               The official name of the network.
  11215.  
  11216.  
  11217.          n_aliases           A  zero  terminated  list  of  alternate
  11218.                               names for the network.
  11219.  
  11220.  
  11221.          n_addrtype           The type of the network number returned;
  11222.                               currently only AF_INET.
  11223.  
  11224.  
  11225.          n_net                The network number.   Network numbers are
  11226.                               returned in machine byte order.
  11227.  
  11228.  
  11229.          Network numbers are supplied in host order.
  11230.  
  11231.  
  11232.          Type specifies the address type to use, currently only
  11233.          AF_INET is supported.
  11234.  
  11235.  
  11236.    DIAGNOSTICS
  11237.          A NULL pointer is returned if no matching entry was found or
  11238.          error occured.
  11239.  
  11240.  
  11241. System Manual                  AmiTCP/IP                 Section B.4    165
  11242.  
  11243.  
  11244.  
  11245.    BUGS
  11246.          All information is contained in a static area so it must  be
  11247.          copied ifit is to be saved.
  11248.  
  11249.  
  11250.          Only Internet network numbers are currently understood.
  11251.  
  11252.  
  11253.    SEE ALSO
  11254.          AmiTCP/IP configuration
  11255.  
  11256.  
  11257. 166    Section B.4                 AmiTCP/IP                  System Manual
  11258.  
  11259.  
  11260.  
  11261. B.4.3   getprotobyname()
  11262.  
  11263.    NAME
  11264.          getprotobyname, getprotobynumber - get protocol entry
  11265.  
  11266.  
  11267.    SYNOPSIS
  11268.          #include <netdb.h>
  11269.  
  11270.  
  11271.          protoent= getprotobyname(name)
  11272.          D0                         A0
  11273.  
  11274.  
  11275.          struct protoent *getprotobyname(char *);
  11276.  
  11277.  
  11278.          protoent= getprotobynumber(proto)
  11279.          D0                            D0
  11280.  
  11281.  
  11282.          struct protoent *getprotobynumber(long);
  11283.  
  11284.  
  11285.    DESCRIPTION
  11286.          getprotobyname() and getprotobynumber() both return a pointer
  11287.          to  an  object with the  following structure  containing  the
  11288.          broken-out fields of a line in netdb configuration file
  11289.  
  11290.  
  11291.            struct    protoent -
  11292.              char *p_name;       /* official name of protocol */
  11293.              char **p_aliases;   /* alias list */
  11294.              int  p_proto;       /* protocol number */
  11295.           ";
  11296.  
  11297.  
  11298.          The members of this structure are:
  11299.  
  11300.  
  11301.          p_name               The official name of the protocol.
  11302.          p_aliases           A  zero  terminated  list  of  alternate
  11303.                               names for the protocol.
  11304.          p_proto             The protocol number.
  11305.  
  11306.  
  11307.  
  11308.    DIAGNOSTICS
  11309.          A NULL pointer is returned if no matching entry was found or
  11310.          error occured.
  11311.  
  11312.  
  11313.    BUGS
  11314.          All information is contained in a static area so it must  be
  11315.          copied  if  it  is to be saved.  Only the Internet protocols
  11316.          are currently understood.
  11317.  
  11318.  
  11319.    SEE ALSO
  11320.          AmiTCP/IP configuration
  11321.  
  11322.  
  11323. System Manual                  AmiTCP/IP                 Section B.4    167
  11324.  
  11325.  
  11326.  
  11327. B.4.4   getservbyname()
  11328.  
  11329.  
  11330.  
  11331.    NAME
  11332.          getservbyname, getservbyport - get service entry
  11333.  
  11334.  
  11335.    SYNOPSIS
  11336.          #include <netdb.h>
  11337.  
  11338.  
  11339.          servent =getservbyname(name, proto)
  11340.          D0                       A0     A1
  11341.  
  11342.  
  11343.          struct servent *getservbyname(char *, char *)
  11344.  
  11345.  
  11346.          servent =getservbyport(port, proto)
  11347.          D0                       D0     A0
  11348.  
  11349.  
  11350.          struct servent *getservbyport(long, char *);
  11351.  
  11352.  
  11353.    DESCRIPTION
  11354.          getservbyname() and getservbyport() both return a pointer  to
  11355.          an   object  with  the  following  structure  containing  the
  11356.          broken-out fields of a line in netdb configuration file.
  11357.  
  11358.  
  11359.            struct    servent -
  11360.              char *s_name;       /* official name of service */
  11361.              char **s_aliases;   /* alias list */
  11362.              int  s_port;         /*port service resides at */
  11363.              char *s_proto;      /* protocol to use */
  11364.            ";
  11365.  
  11366.  
  11367.          The members of this structure are:
  11368.               s_name               The official name of the service.
  11369.               s_aliases            A zero terminated list of alternate
  11370.                                    names for the service.
  11371.               s_port               The port number at which  the  ser-
  11372.                                    vice  resides.    Port numbers  are
  11373.                                    returned  in  network  short   byte
  11374.                                    order.
  11375.               s_proto              The name of  the  protocol  to  use
  11376.                                    when contacting the service.
  11377.  
  11378.  
  11379.          The protoargument specifies the protocol for which to the
  11380.          sercive is to use. It is a normal C string, e.g. "tcp" or
  11381.          "udp".
  11382.  
  11383.  
  11384.    DIAGNOSTICS
  11385.          A NULL pointer is returned if no matching entry was found or
  11386.          error occured.
  11387.  
  11388.  
  11389.    BUGS
  11390.          All information is contained in a static area so it must  be
  11391.  
  11392.  
  11393. 168    Section B.4                 AmiTCP/IP                  System Manual
  11394.  
  11395.  
  11396.  
  11397.          copied  if it is to be saved.  Expecting port numbers to fit
  11398.          in a 32 bit quantity is probably naive.
  11399.  
  11400.  
  11401.    SEE ALSO
  11402.          AmiTCP/IP configuration
  11403.  
  11404.  
  11405. System Manual                  AmiTCP/IP                 Section B.5    169
  11406.  
  11407.  
  11408.  
  11409. B.5     AmiTCP/IP  Specific Extensions
  11410.  
  11411.  
  11412. B.5.1   Errno()
  11413.  
  11414.    NAME
  11415.          Errno - get error value after unsuccessful function call
  11416.  
  11417.  
  11418.    SYNOPSIS
  11419.          errno = Errno()
  11420.          D0
  11421.  
  11422.  
  11423.          LONG Errno(VOID);
  11424.  
  11425.  
  11426.    FUNCTION
  11427.          When  some  function  in  socket  library  return  an  error
  11428.          conditionvalue, they also set a specific error value.  This
  11429.          error value can be extracted by this function.
  11430.  
  11431.  
  11432.    RESULT
  11433.          Error value  indicating  the error on  last failure  of some
  11434.          socket function call.
  11435.  
  11436.  
  11437.    NOTES
  11438.          Return  value  of  Errno()  is not changed  after successful
  11439.          functionso so it cannot be used to determine success of any
  11440.          functioncall  of this library.  Also, another function call
  11441.          to this library may change  the return value of  Errno() so
  11442.          use it right after error occurred.
  11443.  
  11444.  
  11445.    SEE ALSO
  11446.          SetErrnoPtr()
  11447.  
  11448.  
  11449. 170    Section B.5                 AmiTCP/IP                  System Manual
  11450.  
  11451.  
  11452.  
  11453. B.5.2   ObtainSocket()
  11454.  
  11455.    NAME
  11456.          ObtainSocket - get a socket from AmiTCP/IP socket list
  11457.  
  11458.  
  11459.    SYNOPSIS
  11460.          s = ObtainSocket(id, domain, type, protocol)
  11461.          D0                D0  D1      D2     D3
  11462.  
  11463.  
  11464.          LONG ObtainSocket(LONG, LONG, LONG, LONG);
  11465.  
  11466.  
  11467.    FUNCTION
  11468.          When onetask wants to give  a socket to  an another one, it
  11469.          releasesit (with a key value) to a special socket list held
  11470.          by  AmiTCP/IP.    This  function  requests  that  socket  and
  11471.          receivesit if id and other parameters match.
  11472.  
  11473.  
  11474.    INPUTS
  11475.          id       - a key value given by the socket donator.
  11476.          domain   - see documentation of socket().
  11477.          type     - see documentation of socket().
  11478.          protocol- see documentation of socket().
  11479.  
  11480.  
  11481.    RESULT
  11482.          Non negative socket descriptor on success. On failure, -1 is
  11483.          returnedand the errno is set to indicate the error.
  11484.  
  11485.  
  11486.    ERRORS
  11487.          EMFILE          - The per-process descriptor table is
  11488.                             full.
  11489.  
  11490.  
  11491.          EPROTONOSUPPORT - The protocol type or the specified  pro-
  11492.                             tocol is not supported within this
  11493.                             domain.
  11494.  
  11495.  
  11496.          EPROTOTYPE       - The protocol is the wrong type for the
  11497.                             socket.
  11498.  
  11499.  
  11500.          EWOULDBLOCK      - Matching socket is not found.
  11501.  
  11502.  
  11503.    SEE ALSO
  11504.          ReleaseCopyOfSocket(), ReleaseSocket(), socket()
  11505.  
  11506.  
  11507. System Manual                  AmiTCP/IP                 Section B.5    171
  11508.  
  11509.  
  11510.  
  11511. B.5.3   ReleaseCopyOfSocket()
  11512.  
  11513.    NAME
  11514.          ReleaseCopyOfSocket - copy given socket to AmiTCP/IP socket list.
  11515.  
  11516.  
  11517.    SYNOPSIS
  11518.          id = ReleaseCopyOfSocket(fd, id)
  11519.          D0                        D0  D1
  11520.  
  11521.  
  11522.          LONG ReleaseCopyOfSocket(LONG, LONG);
  11523.  
  11524.  
  11525.    FUNCTION
  11526.          Make a new reference to a given socket (pointed by its descriptor)
  11527.          and release it to the socket list held by AmiTCP/IP.
  11528.  
  11529.  
  11530.    INPUTS
  11531.          fd - descriptor of the socket to release.
  11532.  
  11533.  
  11534.          id - thekey value to identify use of this socket. It can be
  11535.               unique or not, depending on its  value. If id value is
  11536.               between 0  and  65535,  inclusively,  it is  considered
  11537.               nonunique  and it can  be  used as a port  number,  for
  11538.               example.   If  id is greater  than  65535 and less than
  11539.               2^31) it  must be unique in currently held sockets  in
  11540.               AmiTCP/IP socket  list,  Otherwise  an  error will  be
  11541.               returned  and  socket  is  not  released.     If  id  ==
  11542.               UNIQUE_ID (defined in <sys/socket.h>) an unique id will
  11543.               be generated.
  11544.  
  11545.  
  11546.    RESULT
  11547.          id - -1 in case of error and the key value of the socket put
  11548.               in the list. Most useful when an uniqueid is generated
  11549.               by this routine.
  11550.  
  11551.  
  11552.    ERRORS
  11553.          EINVAL -Requested unique id is already used.
  11554.  
  11555.  
  11556.          ENOMEM -Needed memory couldn't be allocated.
  11557.  
  11558.  
  11559.    NOTE
  11560.          The socket descriptor is not deallocated.
  11561.  
  11562.  
  11563.    SEE ALSO
  11564.          ObtainSocket(), ReleaseSocket()
  11565.  
  11566.  
  11567. 172    Section B.5                 AmiTCP/IP                  System Manual
  11568.  
  11569.  
  11570.  
  11571. B.5.4   ReleaseSocket()
  11572.  
  11573.    NAME
  11574.          ReleaseSocket - release given socket to AmiTCP/IP socket list.
  11575.  
  11576.  
  11577.    SYNOPSIS
  11578.          id = ReleaseSocket(fd, id)
  11579.          D0                  D0  D1
  11580.  
  11581.  
  11582.          LONG ReleaseSocket(LONG, LONG);
  11583.  
  11584.  
  11585.    FUNCTION
  11586.          Release the reference of given socket (via  its  descriptor)
  11587.          and movethe socket to the  socket  list held by  AmiTCP/IP.
  11588.          The socket descriptor is deallocated in this procedure.
  11589.  
  11590.  
  11591.    INPUTS
  11592.          fd - descriptor of the socket to release.
  11593.  
  11594.  
  11595.          id - thekey value to identify use of this socket. It can be
  11596.               unique or not, depending on its  value. If id value is
  11597.               between 0  and  65535,  inclusively,  it is  considered
  11598.               nonunique  and it can  be  used as a port  number,  for
  11599.               example.   If  id is greater  than  65535 and less than
  11600.               2^31) it  must be unique in currently held sockets  in
  11601.               AmiTCP/IP socket  list,  Otherwise  an  error will  be
  11602.               returned  and  socket  is  not  released.     If  id  ==
  11603.               UNIQUE_ID (defined in <sys/socket.h>) an unique id will
  11604.               be generated.
  11605.  
  11606.  
  11607.    RESULT
  11608.          id - -1 in case of error and the key value of the socket put
  11609.               in the list. Most useful when an uniqueid is generated
  11610.               by this routine.
  11611.  
  11612.  
  11613.    ERRORS
  11614.          EINVAL -Requested unique id is already used.
  11615.  
  11616.  
  11617.          ENOMEM -Needed memory couldn't be allocated.
  11618.  
  11619.  
  11620.    SEE ALSO
  11621.          ObtainSocket(), ReleaseCopyOfSocket()
  11622.  
  11623.  
  11624. System Manual                  AmiTCP/IP                 Section B.5    173
  11625.  
  11626.  
  11627.  
  11628. B.5.5   SetDTableSize()
  11629.  
  11630.    NAME
  11631.          SetDTableSize - set socket descriptor table size of the base
  11632.  
  11633.  
  11634.    SYNOPSIS
  11635.          newsize =SetDTableSize(size)
  11636.          D0                       D0
  11637.  
  11638.  
  11639.          LONG SetDTableSize(UWORD);
  11640.  
  11641.  
  11642.    FUNCTION
  11643.          This  function increases  the  descriptor table size  inside
  11644.          library base so more sockets can be open at the same time.
  11645.  
  11646.  
  11647.    INPUT
  11648.          size - the new size of the desctiptor table.
  11649.  
  11650.  
  11651.    RESULT
  11652.          newsize -the new size of the descriptor table. Note that
  11653.          this canbe less than requested if an error occured.
  11654.  
  11655.  
  11656.    WARNING
  11657.          If the size of fd_set is not adjusted to store the increased
  11658.          space needed for  new  socket descriptors some other  memory
  11659.          will  bespilled.  Change  the  value of  FD_SETSIZE  before
  11660.          including any  socket  include  files  and  don't  increase
  11661.          descriptor  table    to    greater  than  the  new    value  of
  11662.          FD_SETSIZE.
  11663.  
  11664.  
  11665.    SEE ALSO
  11666.          getdtablesize(), select()
  11667.  
  11668.  
  11669. 174    Section B.5                 AmiTCP/IP                  System Manual
  11670.  
  11671.  
  11672.  
  11673. B.5.6   SetErrnoPtr()
  11674.  
  11675.    NAME
  11676.          SetErrnoPtr - set new place where the error value will be written
  11677.  
  11678.  
  11679.    SYNOPSIS
  11680.          SetErrnoPtr(ptr, size)
  11681.                       A0    D0
  11682.  
  11683.  
  11684.          VOID SetErrnoPtr(VOID *, UBYTE);
  11685.  
  11686.  
  11687.    FUNCTION
  11688.          This functions allows caller to redirect error variable inside
  11689.          scope of caller task.    Usually this is  used to make  task's
  11690.          global variable errno as error variable.
  11691.  
  11692.  
  11693.    INPUTS
  11694.          ptr     - pointer to error variable that isto be modified on
  11695.                    every error condition on this library function.
  11696.          size    - size of the error variable.
  11697.  
  11698.  
  11699.    EXAMPLE
  11700.          #include <errno.h>
  11701.  
  11702.  
  11703.          struct Library;
  11704.          struct Library * SocketBase = NULL;
  11705.  
  11706.  
  11707.          int main(void)
  11708.          -
  11709.             ...
  11710.            if ((SocketBase = OpenLibrary("bsdsocket.library", 2))
  11711.                != NULL) -
  11712.              SetErrnoPtr(&errno, sizeof(errno));
  11713.             ...
  11714.            "
  11715.          "
  11716.  
  11717.  
  11718.    NOTES
  11719.          Be sure that this new error variable exists until library base
  11720.          is finally closed or SetErrnoPtr() is called again for another
  11721.          variable.
  11722.  
  11723.  
  11724.    SEE ALSO
  11725.          Errno()
  11726.  
  11727.  
  11728. System Manual                  AmiTCP/IP                 Section B.5    175
  11729.  
  11730.  
  11731.  
  11732. B.5.7   SetSocketSignals()
  11733.  
  11734.    NAME
  11735.          SetSocketSignals - inform AmiTCP/IP of INTR, IO and URG signals
  11736.  
  11737.  
  11738.    SYNOPSIS
  11739.          SetSocketSignals(sigintrmask, sigiomask, sigurgmask)
  11740.                            D0            D1         D2
  11741.  
  11742.  
  11743.          VOID SetSocketSignals(ULONG, ULONG, ULONG);
  11744.  
  11745.  
  11746.    FUNCTION
  11747.          SetSocketSignals()  tells the AmiTCP/IP which  signal  masks
  11748.          corresponds UNIX SIGINT, SIGIO and SIGURG signals to be used
  11749.          in  this implementation.    sigintrmask  mask    is  used  to
  11750.          determine which  Amiga signals  interrupt  blocking library
  11751.          calls.   sigio-  and sigurgmasks  are sent when asynchronous
  11752.          notification of socket events is done and  when  out-of-band
  11753.          data arrives, respectively.
  11754.  
  11755.  
  11756.          Note that the supplied  values write over old ones. If this
  11757.          functionis used and CTRL-C is still wanted to interrupt the
  11758.          calls (the   default behaviour), the value BREAKF_CTRL_C must
  11759.          be explicitly given.
  11760.  
  11761.  
  11762.    SEE ALSO
  11763.          IoctlSocket(), recv(), send(), WaitSelect()
  11764.  
  11765.  
  11766.  
  11767.  
  11768.  
  11769. Appendix C
  11770.  
  11771.  
  11772.  
  11773. AmiTCP/IP  Network Link  Library
  11774.  
  11775.  
  11776.  
  11777. This appendix describes the functions located in the net.lib.
  11778.  
  11779.  
  11780.  
  11781. Table  of  Contents
  11782.  
  11783.  
  11784.         autoinit : : : : : : : : : : : : : : : : : : : : :: : : : : : : : : : :*
  11785.  * : : : : : : : : 177
  11786.         autoinitd : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : :*
  11787.  * : : : :: : : : 178
  11788.         charRead : : : : : : : : : : : : : : : : : : : : :: : : : : : : : : : :*
  11789.  * : : : : : : : : 179
  11790.         gethostname : : : : :: : : : : : : : : : : : : : : : : : : : : : : : : *
  11791.  *: : : : : : : : 181
  11792.         lineRead : : : : : : : : : : : : : : : : : : : : :: : : : : : : : : : :*
  11793.  * : : : : : : : : 182
  11794.  
  11795.  
  11796.  
  11797.                                       176
  11798.  
  11799.  
  11800. System Manual                  AmiTCP/IP                 Section C.1    177
  11801.  
  11802.  
  11803.  
  11804. C.1     net.lib Functions
  11805.  
  11806.  
  11807. C.1.1   autoinit
  11808.  
  11809.    NAME
  11810.         autoinit - SAS C Autoinitialization Functions
  11811.  
  11812.  
  11813.    SYNOPSIS
  11814.         _STIopenSockets()
  11815.  
  11816.  
  11817.         void  _STIopenSockets(void)
  11818.  
  11819.  
  11820.         _STDcloseSockets()
  11821.  
  11822.  
  11823.         void  _STDcloseSockets(void)
  11824.  
  11825.  
  11826.    FUNCTION
  11827.         These functions open and close the bsdsocket.library at the
  11828.         startup and exit of the program, respectively. For a
  11829.         program to use these functions, it must be linked with
  11830.         netlib:net.lib.
  11831.  
  11832.  
  11833.         Ifthe library can be opened, the _STIopenSockets() calls
  11834.         bsdsocket.library function SetErrnoPtr() to tell the
  11835.         library the address and the size of the errno variable of
  11836.         thecalling program.
  11837.  
  11838.  
  11839.    NOTES
  11840.         _STIopenSockets() also checks that the system version is at
  11841.         least 37. It puts up a requester if the bsdsocket.library
  11842.         isnot found or is of wrong version.
  11843.  
  11844.  
  11845.         Theautoinitialization and autotermination functions are
  11846.         features specific to the SAS C6. However, these functions
  11847.         canbe used with other (ANSI) C compilers, too. Example
  11848.         follows:
  11849.  
  11850.  
  11851.         "*at start of main() *"
  11852.  
  11853.  
  11854.         atexit(_STDcloseSockets);
  11855.         _STDopenSockets();
  11856.  
  11857.  
  11858.    BUGS
  11859.  
  11860.  
  11861.    SEE ALSO
  11862.         bsdsocket.library/SetErrnoPtr(),
  11863.         SAS/C 6 User's Guide p. 145 for details of
  11864.         autoinitialization and autotermination functions.
  11865.  
  11866.  
  11867. 178    Section C.1                 AmiTCP/IP                  System Manual
  11868.  
  11869.  
  11870.  
  11871. C.1.2   autoinitd
  11872.  
  11873.    NAME
  11874.         autoinitd - SAS C Autoinitialization Functions for Daemons
  11875.  
  11876.  
  11877.    SYNOPSIS
  11878.         void  _STIopenSockets(void);
  11879.         void  _STDcloseSockets(void);
  11880.         long  server_socket;
  11881.  
  11882.  
  11883.    DESCRIPTION
  11884.         These are SASC autoinitialization functions for internet daemons
  11885.         started by inetd, Internet super-server. Upon startup, the server
  11886.         socket is obtained with ObtainSocket() library call. If successful,
  11887.         thesocket id is stored to the global variable server_socket. If the
  11888.         socket is not obtainable, the server_socket contains value -1.
  11889.         Ifthe server_socket is not valid, the server may try to accept() a
  11890.         newconnection and act as a stand-alone server.
  11891.  
  11892.  
  11893.    RESULT
  11894.         server_socket - positive socket id for success or -1 for failure.
  11895.  
  11896.  
  11897.    NOTES
  11898.         _STIopenSockets() also checks that the system version is at
  11899.         least 37. It puts up a requester if the bsdsocket.library
  11900.         isnot found or is of wrong version.
  11901.  
  11902.  
  11903.         Theautoinitialization and autotermination functions are
  11904.         features specific to the SAS C6. However, these functions
  11905.         canbe used with other (ANSI) C compilers, too. Example
  11906.         follows:
  11907.  
  11908.  
  11909.         "*at start of main() *"
  11910.  
  11911.  
  11912.         atexit(_STDcloseSockets);
  11913.         _STDopenSockets();
  11914.  
  11915.  
  11916.    AUTHOR
  11917.         Jarno Rajahalme, Pekka Pessi,
  11918.         theAmiTCP/IP Group <amitcp-group@hut.fi>,
  11919.         Helsinki University of Technology, Finland.
  11920.  
  11921.  
  11922.    SEE ALSO
  11923.         serveraccept(), netutil/inetd
  11924.  
  11925.  
  11926. System Manual                  AmiTCP/IP                 Section C.1    179
  11927.  
  11928.  
  11929.  
  11930. C.1.3   charRead
  11931.  
  11932.  
  11933.    NAME
  11934.         charRead -- read characters from socket one by one.
  11935.  
  11936.  
  11937.    SYNOPSIS
  11938.         initCharRead(rc, fd)
  11939.  
  11940.  
  11941.         void initCharRead(struct CharRead *, int);
  11942.  
  11943.  
  11944.  
  11945.         character = charRead(rc)
  11946.  
  11947.  
  11948.         intcharRead(struct CharRead *);
  11949.  
  11950.  
  11951.  
  11952.    DESCRIPTION
  11953.         charRead is a macro package which return characters one by one
  11954.         from given socket input stream. The socket where data is to be read
  11955.         isset by calling initCharRead(): rc is the pointer to charread
  11956.         structure previously allocated. fd is the (socket) descriptor where
  11957.         reading is to be done.
  11958.  
  11959.  
  11960.         charRead() returns the next character from input stream or one of
  11961.         the following:
  11962.  
  11963.  
  11964.         RC_DO_SELECT     (-3)     - read input buffer is returned. Do select
  11965.                                    before next call if you don't want charread
  11966.                                    to  block.
  11967.  
  11968.  
  11969.         RC_EOF           (-2)    - end-of-file condition has occurred.
  11970.  
  11971.  
  11972.         RC_ERROR         (-1)    - there has been an error while filling new
  11973.                                    charread buffer. Check the value of Errno()
  11974.  
  11975.  
  11976.    NOTE
  11977.         Always use variable of type int to store return value from charRead()
  11978.         since the numeric value of characters returned may vary between
  11979.         0 -255 (or even greater). As you may know, -3 equals 253 if of type
  11980.         unsigned char.
  11981.  
  11982.  
  11983.    EXAMPLE
  11984.         /*
  11985.          * This piece of code shows how to use charread with select()
  11986.          */
  11987.         #include <sys/types.h>
  11988.         #include <sys/socket.h>
  11989.         #include <charread.h>
  11990.  
  11991.  
  11992.         main_loop(int sock)
  11993.         -
  11994.           struct CharReadrc;
  11995.           fd_set readfds;
  11996.           int c;
  11997.  
  11998.  
  11999.           initCharRead(&rc,  sock);
  12000.  
  12001.  
  12002. 180    Section C.1                 AmiTCP/IP                  System Manual
  12003.  
  12004.  
  12005.  
  12006.           FD_ZERO(&readfds);
  12007.  
  12008.  
  12009.           while(1) -
  12010.             FD_SET(sock, &readfds);
  12011.  
  12012.  
  12013.             if (select(sock + 1. &readfds, NULL, NULL, NULL)) < 0) -
  12014.               perror("select");
  12015.               break;
  12016.             "
  12017.             if (FD_ISSET(sock, &readfds)) -
  12018.               while((c = charRead(&rc)) >= 0)
  12019.                 handle_next_input_character(c);
  12020.               if (c == RC_EOF)
  12021.                 break;
  12022.               if (c == RC_ERROR) -
  12023.                 perror("charRead");
  12024.                 break;
  12025.               "
  12026.             "
  12027.           "
  12028.         "
  12029.  
  12030.  
  12031.     PORTABILITY
  12032.         Thesource file charread.h should be able to be used in
  12033.         UNIX programs as is.
  12034.  
  12035.  
  12036.     AUTHORS
  12037.         Tomi  Ollila,
  12038.         theAmiTCP/IP Group <amitcp-group@hut.fi>,
  12039.  
  12040.  
  12041.     SEE ALSO
  12042.         lineRead(), bsdsocket.library/recv()
  12043.  
  12044.  
  12045. System Manual                  AmiTCP/IP                 Section C.1    181
  12046.  
  12047.  
  12048.  
  12049. C.1.4   gethostname
  12050.  
  12051.    NAME
  12052.         gethostname -- get the name of the host
  12053.  
  12054.  
  12055.    SYNOPSIS
  12056.         error = gethostname(name, namelen);
  12057.  
  12058.  
  12059.         intgethostname(char *, int);
  12060.  
  12061.  
  12062.    FUNCTION
  12063.         Getthe name of the host to the buffer name of length namelen.
  12064.         Thename is taken from the environment variable "HOSTNAME"
  12065.         where it SHOULD reside.
  12066.  
  12067.  
  12068.    INPUTS
  12069.         name     - Pointer to the buffer where the name should be
  12070.                   stored.
  12071.         namelen - Length of the buffer name.
  12072.  
  12073.  
  12074.    RESULT
  12075.         error    - 0 on success,-1 in case of an error. The global
  12076.                   variable errno will be set to indicate the error as
  12077.                   follows:
  12078.  
  12079.  
  12080.                   ENOENT - The environment variable "HOSTNAME" is not
  12081.                             found.
  12082.  
  12083.  
  12084.    EXAMPLE
  12085.         char  hostname[MAXHOSTNAMELEN];
  12086.         int error;
  12087.  
  12088.  
  12089.         error = gethostname(hostname, sizeof(hostname));
  12090.         if(error < 0)
  12091.           exit(10);
  12092.  
  12093.  
  12094.         printf("My name is ""%s""."n", hostname);
  12095.  
  12096.  
  12097.    NOTES
  12098.         This function is included for source compatibility with Unix
  12099.         systems.
  12100.         TheENOENT errno value is AmiTCP/IP addition.
  12101.  
  12102.  
  12103.    BUGS
  12104.         Unlike the Unix version, this version assures that the
  12105.         resulting string is always NULL-terminated.
  12106.  
  12107.  
  12108.    SEE ALSO
  12109.         getenv()
  12110.  
  12111.  
  12112. 182    Section C.1                 AmiTCP/IP                  System Manual
  12113.  
  12114.  
  12115.  
  12116. C.1.5   lineRead
  12117.  
  12118.  
  12119.    NAME
  12120.         lineRead -- read newline terminated strings from socket
  12121.  
  12122.  
  12123.    SYNOPSIS
  12124.         initLineRead(rl, fd, lftype, bufsize)
  12125.  
  12126.  
  12127.         void initLineRead(struct LineRead *, int, int, int);
  12128.  
  12129.  
  12130.  
  12131.         length = lineRead(rl)
  12132.  
  12133.  
  12134.         intlineread(struct LineRead *);
  12135.  
  12136.  
  12137.  
  12138.    DESCRIPTION
  12139.         lineRead() reads newline terminated strings from given descriptor
  12140.         very efficiently. All the options needed are set by calling
  12141.         initLineRead(): rl is the pointer to lineread structure previously
  12142.         allocated. fd is the (socket) descriptor where reading is to be
  12143.         done. lftype can have following 3 values:
  12144.  
  12145.  
  12146.             RL_LFNOTREQ - Newline terminated strings are returned unless
  12147.                            there is no newlines left in currently buffered
  12148.                            input. In this case remaining buffer is returned.
  12149.  
  12150.  
  12151.             RL_LFREQLF  - If there is no newlines left in currently buffered
  12152.                            input the remaining input datais copied at the
  12153.                            start of buffer. Caller is informed that next
  12154.                            call will fill the buffer (andit may block).
  12155.                            Lines are always returned withnewline at the end
  12156.                            unless the string is longer than whole buffer.
  12157.  
  12158.  
  12159.             RL_LFREQNUL  - Like LF_REQLF, but remaining newline is removed.
  12160.                            Note here that lenght is one longer that actual
  12161.                            string length since line that has only one
  12162.                            newline at the end would returnlength as 0
  12163.                            which indigate string incomplete condition.
  12164.  
  12165.  
  12166.         bufsize is used to tell lineread how big the receive buffer is.
  12167.         always put RL_BUFSIZE here since that value is used to determine
  12168.         thememory allocated for the buffer. This option is given to you
  12169.         soyou may decide to use different buffer size than the default
  12170.         1024.
  12171.  
  12172.  
  12173.         lineRead() returns the newline terminated string in rl_line field
  12174.         oflineread structure. Return values of lineRead() are:
  12175.  
  12176.  
  12177.              1 - RL_BUFSIZE     - normal length of returned string.
  12178.  
  12179.  
  12180.              0                   - If zero is returned just after select(),
  12181.                                    end-of-file condition has occurred.
  12182.                                    Otherwise string is not completed yet.
  12183.                                    Make sure you call select() (or use non-
  12184.                                    blocking IO) if you don't want next call
  12185.  
  12186.  
  12187. System Manual                  AmiTCP/IP                 Section C.1    183
  12188.  
  12189.  
  12190.  
  12191.                                    to  block.
  12192.  
  12193.  
  12194.             -1                   - if rl_Line field of lineread structure
  12195.                                    is NULL, it indicates error condition.
  12196.                                    If rl_Line points to start of string
  12197.                                    buffer, input string has been longer
  12198.                                    than buffer. In this case rl_Line points
  12199.                                    to zero terminated string of length
  12200.                                    RL_BUFSIZE.
  12201.  
  12202.  
  12203.         Youmay modify the zero terminated string returned by lineRead() in
  12204.         anyway, but memory around the string is private lineread memory.
  12205.  
  12206.  
  12207.    EXAMPLE
  12208.         /*
  12209.          * The following code shows how to use lineread with select()
  12210.          */
  12211.         #ifdef  USE_LOW_MEMORY_BUFFER
  12212.         #define RL_BUFSIZE 256
  12213.         #endif
  12214.  
  12215.  
  12216.         #include <sys/types.h>
  12217.         #ifdef  AMIGA
  12218.         #include <bsdsocket.h>
  12219.         #endif
  12220.         #include <lineread.h>
  12221.  
  12222.  
  12223.         #define NULL 0
  12224.  
  12225.  
  12226.         ...
  12227.  
  12228.  
  12229.         main_loop(int sock)
  12230.         -
  12231.           struct LineRead* rl;
  12232.           int length;
  12233.           fd_set reafdfs;
  12234.  
  12235.  
  12236.           if (rl = (struct LineRead *)AllocMem(sizeof (*rl), 0)) -
  12237.  
  12238.  
  12239.             initLineRead(rl, sock, LF_REQLF, RL_BUFSIZE);
  12240.  
  12241.  
  12242.             FD_ZERO(&readfds);
  12243.  
  12244.  
  12245.             while(1) -
  12246.               FD_SET(sock, &readfds);
  12247.  
  12248.  
  12249.               if (select(sock + 1, &readfds, NULL, NULL, NULL)) < 0) -
  12250.                 perror("select");
  12251.                 break;
  12252.               "
  12253.               if (FD_ISSET(sock, &readfds))
  12254.                 if ((length = lineRead(rl)) == 0) /* EOF */
  12255.                   break;
  12256.                 do -
  12257.                   if (length > 0)
  12258.  
  12259.  
  12260. 184    Section C.1                 AmiTCP/IP                  System Manual
  12261.  
  12262.  
  12263.  
  12264.                     write(1, rl->rl_Line, length); /* stdout. write() for */
  12265.                                                       /* speed demonstration*/
  12266.                   else - /* length == -1 */
  12267.                     if (rl->rl_Line == NULL); -
  12268.                        perror("lineRead");
  12269.                        break;
  12270.                     "
  12271.                     else -
  12272.                        fprintf(stderr, "lineread input buffer overflow!"n");
  12273.                        write(1, rl->rl_Line, RL_BUFSIZE);
  12274.                        write(1, ""n", 1);
  12275.                     "
  12276.                   "
  12277.                 " while ((length = lineRead(rl)) != 0); /* 0 -> doselect() */
  12278.             "
  12279.           FreeMem(rl, sizeof (*rl);
  12280.           "
  12281.           else
  12282.             fprintf("AllocMem: Out Of memory"n");
  12283.         "
  12284.  
  12285.  
  12286.     PORTABILITY
  12287.         Thesource modules lineread.c and lineread.h should compile
  12288.         inUNIX machines as is.
  12289.  
  12290.  
  12291.     AUTHORS
  12292.         Tomi  Ollila,
  12293.         theAmiTCP/IP Group <amitcp-group@hut.fi>,
  12294.  
  12295.  
  12296.     SEE ALSO
  12297.         readChar(), bsdsocket.library/recv()
  12298.  
  12299.  
  12300.  
  12301.  
  12302.  
  12303. Appendix D
  12304.  
  12305.  
  12306.  
  12307. Protocols  and  Network Interfaces
  12308.  
  12309.  
  12310.  
  12311. The AutoDoc file protocol.doc contains on-line manual pages for protocols
  12312. and network interfaces.
  12313.  
  12314.  
  12315.  
  12316. Table  of  Contents
  12317.  
  12318.  
  12319.         arp : : : : : : : :: : : : : : : : : : : : : : : : : : : : : : : : : : *
  12320.  *: : : : : : : : : : 186
  12321.         icmp : : : : : : : : : : : : : : : : : : : : : :: : : : : : : : : : : :*
  12322.  * : : : : : : : : : 189
  12323.         if  : : : : : : : : : : :: : : : : : : : : : : : : : : : : : : : : : : *
  12324.  *: : : : : : : : : : 190
  12325.         inet : : : : : : : : : : : : : : : : : : : : : :: : : : : : : : : : : :*
  12326.  * : : : : : : : : : 193
  12327.         ip  : : : : : : : : : : :: : : : : : : : : : : : : : : : : : : : : : : *
  12328.  *: : : : : : : : : : 196
  12329.         lo  : : : : : : : : : : :: : : : : : : : : : : : : : : : : : : : : : : *
  12330.  *: : : : : : : : : : 198
  12331.         routing : : : : : : :: : : : : : : : : : : : : : : : : : : : : : : : : *
  12332.  *: : : : : : : : : 199
  12333.         tcp : : : : : : : :: : : : : : : : : : : : : : : : : : : : : : : : : : *
  12334.  *: : : : : : : : : : 201
  12335.         udp : : : : : : : :: : : : : : : : : : : : : : : : : : : : : : : : : : *
  12336.  *: : : : : : : : : : 203
  12337.  
  12338.  
  12339.  
  12340.                                       185
  12341.  
  12342.  
  12343. 186    Section D.1                 AmiTCP/IP                  System Manual
  12344.  
  12345.  
  12346.  
  12347. D.1     Protocols  and  Network  Interfaces
  12348.  
  12349.  
  12350.  
  12351. D.1.1   arp
  12352.  
  12353.  
  12354.    NAME
  12355.         arp- Address Resolution Protocol
  12356.  
  12357.  
  12358.    CONFIG
  12359.         AnySANA-II device driver using ARP
  12360.  
  12361.  
  12362.    SYNOPSIS
  12363.         #include <sys/socket.h>
  12364.         #include <net/if_arp.h>
  12365.         #include <netinet/in.h>
  12366.  
  12367.  
  12368.         s =socket(AF_INET, SOCK_DGRAM, 0);
  12369.  
  12370.  
  12371.    DESCRIPTION
  12372.         ARPis a protocol used to dynamically map between Internet
  12373.         Protocol (IP) and hardware addresses. It can be used by most
  12374.         theSANA-II network interface drivers. The current
  12375.         implementation supports only Internet Protocol (and is tested
  12376.         only with Ethernet).  However, ARP is not limited to only that
  12377.         combination.
  12378.  
  12379.  
  12380.         ARPcaches IP-to-hardware address mappings. When an interface
  12381.         requests a mapping for an address not in the cache, ARP queues
  12382.         themessage which requires the mapping and broadcasts a
  12383.         message on the associated network requesting the address
  12384.         mapping. If a response is provided, the new mapping is cached
  12385.         andany pending message is transmitted. ARP will queue at most
  12386.         onepacket while waiting for a mapping request to be responded
  12387.         to;only the most recently transmitted packet is kept.
  12388.  
  12389.  
  12390.         Theaddress mapping caches are separate for each interface. The
  12391.         amount of mappings in the cache may be specified with an
  12392.         IoctlSocket() request.
  12393.  
  12394.  
  12395.         Tofacilitate communications with systems which do not use ARP,
  12396.         IoctlSocket() requests are provided to enter and delete entries
  12397.         inthe IP-to-Ethernet tables.
  12398.  
  12399.  
  12400.    USAGE
  12401.         #include <sys/ioctl.h>
  12402.         #include <sys/socket.h>
  12403.         #include <net/if.h>
  12404.         #include <net/if_arp.h>
  12405.  
  12406.  
  12407.         struct arpreq arpreq;
  12408.  
  12409.  
  12410.         IoctlSocket(s, SIOCSARP, (caddr_t)&arpreq);
  12411.         IoctlSocket(s, SIOCGARP, (caddr_t)&arpreq);
  12412.         IoctlSocket(s, SIOCDARP, (caddr_t)&arpreq);
  12413.  
  12414.  
  12415.         These three IoctlSocket()s take the same structure as an argument.
  12416.  
  12417.  
  12418. System Manual                  AmiTCP/IP                 Section D.1    187
  12419.  
  12420.  
  12421.  
  12422.         SIOCSARP sets an ARP entry, SIOCGARP gets an ARP entry, and SIOCDARP
  12423.         deletes an ARP entry. These IoctlSocket() requests may be applied to
  12424.         anysocket descriptor (s). The arpreq structure contains:
  12425.  
  12426.  
  12427.         /*Maximum number of octets in protocol/hw address */
  12428.         #define  MAXADDRARP   16
  12429.  
  12430.  
  12431.         /*
  12432.          * ARP ioctl request.
  12433.          */
  12434.         struct arpreq -
  12435.                 struct  sockaddr arp_pa;  /* protocol address */
  12436.                 struct  -                  /* hardware address */
  12437.                   u_char sa_len;          /* actual length + 2 */
  12438.                   u_char sa_family;
  12439.                   char   sa_data[MAXADDRARP];
  12440.                 "  arp_ha;
  12441.                 int     arp_flags;                     /* flags */
  12442.         ";
  12443.  
  12444.  
  12445.         /*  arp_flags andat_flags field values */
  12446.         #define ATF_INUSE        0x01          /* entry in use */
  12447.         #define ATF_COM         0x02        /* completed entry */
  12448.         #define ATF_PERM        0x04        /* permanent entry */
  12449.         #define ATF_PUBL         0x08          /* publish entry */
  12450.  
  12451.  
  12452.  
  12453.         Theinterface whose ARP table is manipulated is specified by
  12454.         arp_pa sockaddr. The address family for the arp_pa sockaddr
  12455.         must be AF_INET; for the arp_ha sockaddr it must be AF_UNSPEC.
  12456.         Thelength of arp_ha must match the length of used hardware
  12457.         address. Maximum length for the hardware address is MAXADDRARP
  12458.         bytes. The only flag bits which may be written are ATF_PERM
  12459.         andATF_PUBL. ATF_PERM makes the entry permanent if the
  12460.         IoctlSocket() call succeeds. ATF_PUBL specifies that the ARP
  12461.         code should respond to ARP requests for the indicated host
  12462.         coming from other machines.  This allows a host to act as an
  12463.         ARPserver which may be useful in convincing an ARP-only
  12464.         machine to talk to a non-ARP machine.
  12465.  
  12466.  
  12467.    UNSUPPORTED IN AmiTCP/IP
  12468.  
  12469.  
  12470.    AmiTCP/IP EXTENSIONS
  12471.         There is an extension to the standard BSD4.4 ARP ioctl interface to
  12472.         access the contents of the whole ARP mapping cache. (In the BSD4.4
  12473.         thestatic ARP table is accessed via the /dev/kmem.) The SIOCGARPT
  12474.         ioctl takes the following arptabreq structure as an argument:
  12475.  
  12476.  
  12477.         /*
  12478.          * An AmiTCP/IP specific ARP table ioctl request
  12479.          */
  12480.         struct arptabreq -
  12481.                 struct arpreq atr_arpreq;  /* To identify the interface */
  12482.                 long   atr_size;           /* # of elements in atr_table */
  12483.                  long   atr_inuse;                 /* # of elements in use */
  12484.  
  12485.  
  12486. 188    Section D.1                 AmiTCP/IP                  System Manual
  12487.  
  12488.  
  12489.  
  12490.                 struct arpreq *atr_table;
  12491.         ";
  12492.  
  12493.  
  12494.         Theatr_arpreq specifies the used interface. The hardware address
  12495.         forthe interface is returned in the arp_ha field of atr_arpreq
  12496.         structure.
  12497.  
  12498.  
  12499.         TheSIOCGARPT ioctl reads at most atr_size entries from the cache
  12500.         into the user supplied buffer atr_table, if it is not NULL. Actual
  12501.         amount of returned entries is returned in atr_size. The current
  12502.         amount of cached mappings is returned in the atr_inuse.
  12503.  
  12504.  
  12505.         TheSIOCGARPT ioctl has following usage:
  12506.  
  12507.  
  12508.         struct arpreq cache[N];
  12509.         struct arptabreq arptab = - N, 0, cache ";
  12510.  
  12511.  
  12512.         IoctlSocket(s, SIOCGARPT, (caddr_t)&arptabreq);
  12513.  
  12514.  
  12515.    DIAGNOSTICS
  12516.         ARPwatches passively for hosts impersonating the local host
  12517.         (that  is,  a  host which responds to an ARP mapping request
  12518.         forthe local host's address).
  12519.  
  12520.  
  12521.         "duplicate IP address a.b.c.d!!"
  12522.         "sent from hardware address: %x:%x:...:%x:%x"
  12523.  
  12524.  
  12525.         ARP has  discovered  another host on the local network
  12526.         which responds to mapping requests for its own Internet
  12527.         address.
  12528.  
  12529.  
  12530.    BUGS
  12531.         TheARP is tested only with Ethernet. Other network hardware may
  12532.         require special ifconfig configuration.
  12533.  
  12534.  
  12535.    SEE ALSO
  12536.         inet, netutil/arp, netutil/ifconfig, <net/if_arp.h>
  12537.  
  12538.  
  12539.         Plummer, Dave, ``An  Ethernet  Address  Resolution  Protocol
  12540.         -or-   ConvertingNetwork Protocol Addresses to 48.bit Ether-
  12541.         netAddresses for Transmission on Ethernet  Hardware,''  RFC
  12542.         826,  Network  Information  Center, SRI International, Menlo
  12543.         Park, Calif., November 1982. (Sun 800-1059-10)
  12544.  
  12545.  
  12546. System Manual                  AmiTCP/IP                 Section D.1    189
  12547.  
  12548.  
  12549.  
  12550. D.1.2   icmp
  12551.  
  12552.    NAME
  12553.         icmp - Internet Control Message Protocol
  12554.  
  12555.  
  12556.    SYNOPSIS
  12557.         #include <sys/socket.h>
  12558.         #include <netinet/in.h>
  12559.  
  12560.  
  12561.         int
  12562.         socket(AF_INET, SOCK_RAW, proto)
  12563.  
  12564.  
  12565.    DESCRIPTION
  12566.         ICMP is the error and control message protocol used by IP and the
  12567.         Internet protocol family.  It may be accessed through a ``raw
  12568.         socket'' for network monitoring and diagnostic functions.  The proto
  12569.         parameter to the socket call to create an ICMP socket is obtained
  12570.         from getprotobyname().  ICMP sockets are connectionless, and are
  12571.         normally used with the sendto() and recvfrom() calls, though the
  12572.         connect() call may also be used to fix the destination for future
  12573.         packets (in which case the recv() and send() socket library calls
  12574.         maybe used).
  12575.  
  12576.  
  12577.         Outgoing packets automatically have an IP header prepended to them
  12578.         (based on the destination address).  Incoming packets are received
  12579.         with the IP header and options intact.
  12580.  
  12581.  
  12582.    DIAGNOSTICS
  12583.         A socket operation may fail with one of the following errors
  12584.         returned:
  12585.  
  12586.  
  12587.         [EISCONN]         when trying to establish a connection ona socket
  12588.                           which already has one, orwhen trying to send a
  12589.                           datagram with the destination address specified and
  12590.                           the socket is already connected;
  12591.  
  12592.  
  12593.         [ENOTCONN]        when trying tosend a datagram, but no destination
  12594.                           address is specified, andthe socket hasn't been
  12595.                           connected;
  12596.  
  12597.  
  12598.         [ENOBUFS]         when the system runs out of memory for aninternal
  12599.                           data structure;
  12600.  
  12601.  
  12602.         [EADDRNOTAVAIL]  when an attempt is made to create a socket with a
  12603.                           network address for whichno network interface
  12604.                           exists.
  12605.  
  12606.  
  12607.    SEE ALSO
  12608.         bsdsocket.library/send(),  bsdsocket.library/recv(), inet,  ip
  12609.  
  12610.  
  12611.    HISTORY
  12612.         Theicmp protocol is originally from 4.3BSD.
  12613.  
  12614.  
  12615. 190    Section D.1                 AmiTCP/IP                  System Manual
  12616.  
  12617.  
  12618.  
  12619. D.1.3   if
  12620.  
  12621.  
  12622.    NAME
  12623.         if- Network Interface to SANA-II devices
  12624.  
  12625.  
  12626.    DESCRIPTION
  12627.         Each network interface in the AmiTCP/IP corresponds to a path
  12628.         through which messages may be sent and received.  A network
  12629.         interface usually has a SANA-II device driver associated with it,
  12630.         though the loopback interface, "lo", do not. The network interface
  12631.         inthe AmiTCP/IP (sana_softc) is superset of the BSD Unix network
  12632.         interface.
  12633.  
  12634.  
  12635.         When the network interface is first time referenced, AmiTCP/IP tries
  12636.         toopen the corresponding SANA-II device driver. If successful, a
  12637.         software interface to the SANA-II device is created. The "network/"
  12638.         prefix is added to the SANA-II device name, if needed. Once the
  12639.         interface has acquired its address, it is expected to install a
  12640.         routing table entry so that messages can be routed through it.
  12641.  
  12642.  
  12643.         TheSANA-II interfaces must be configured before they will allow
  12644.         traffic to flow through them. It is done after the interface is
  12645.         assigned a protocol address with a SIOCSIFADDR ioctl. Some
  12646.         interfaces may use the protocol address or a part of it as their
  12647.         hardware address. On interfaces where the network-link layer address
  12648.         mapping is static, only the network number is taken from the ioctl;
  12649.         theremainder is found in a hardware specific manner. On interfaces
  12650.         which provide dynamic network-link layer address mapping facilities
  12651.         (for example, Ethernets or Arcnets using ARP), the entire address
  12652.         specified in the ioctl is used.
  12653.  
  12654.  
  12655.         Thefollowing ioctl calls may be used to manipulate network
  12656.         interfaces. Unless specified otherwise, the request takes an ifreq
  12657.         structure as its parameter. This structure has the form
  12658.  
  12659.  
  12660.         struct ifreq -
  12661.           char ifr_name[IFNAMSIZ]; /* interface name (eg. "slip.device/0")*/
  12662.           union -
  12663.             struct sockaddr ifru_addr;
  12664.             struct sockaddr ifru_dstaddr;
  12665.             short            ifru_flags;
  12666.           " ifr_ifru;
  12667.         #define ifr_addr     ifr_ifru.ifru_addr                   /* address */
  12668.         #define ifr_dstaddr ifr_ifru.ifru_dstaddr   /* end of p-to-p link */
  12669.         #define ifr_flags    ifr_ifru.ifru_flags                    /* flags */
  12670.         ";
  12671.  
  12672.  
  12673.         SIOCSIFADDR       Set interface address. Following the address
  12674.                           assignment, the ``initialization'' routine for
  12675.                           the interface is called.
  12676.  
  12677.  
  12678.         SIOCGIFADDR       Get interface address.
  12679.  
  12680.  
  12681.         SIOCSIFDSTADDR    Set point to point address for interface.
  12682.  
  12683.  
  12684.         SIOCGIFDSTADDR    Get point to point address for interface.
  12685.  
  12686.  
  12687. System Manual                  AmiTCP/IP                 Section D.1    191
  12688.  
  12689.  
  12690.  
  12691.         SIOCSIFFLAGS      Set interface flagsfield. If the interface is
  12692.                           marked down, any processes currently routing
  12693.                           packets through the interface are notified.
  12694.  
  12695.  
  12696.         SIOCGIFFLAGS      Get interface flags.
  12697.  
  12698.  
  12699.         SIOCGIFCONF       Get interface configurationlist. This request
  12700.                           takes an ifconf structure(see below) as a
  12701.                           value-result parameter. The ifc_len field should be
  12702.                           initially set to the sizeof the buffer pointed to
  12703.                           by ifc_buf. On return itwill contain the length,
  12704.                           in bytes, of the configuration list.
  12705.  
  12706.  
  12707.         /*
  12708.          * Structure used in SIOCGIFCONF request.
  12709.          * Used toretrieve interface configuration
  12710.          * for machine (useful for programs which
  12711.          * must know all networks accessible).
  12712.          */
  12713.         struct ifconf -
  12714.           int  ifc_len;                       /* size of associated buffer */
  12715.           union -
  12716.             caddr_t       ifcu_buf;
  12717.             struct ifreq *ifcu_req;
  12718.           " ifc_ifcu;
  12719.         #define ifc_buf ifc_ifcu.ifcu_buf                /* buffer address */
  12720.         #define ifc_req ifc_ifcu.ifcu_req /* array of structures returned */
  12721.         ";
  12722.  
  12723.  
  12724.  
  12725.    UNSUPPORTED IN AmiTCP/IP
  12726.         These standard BSD ioctl codes are not currently supported:
  12727.  
  12728.  
  12729.         SIOCADDMULTI      Enable a multicast address for the interface.
  12730.  
  12731.  
  12732.         SIOCDELMULTI      Disable a previouslyset multicast address.
  12733.  
  12734.  
  12735.         SIOCSPROMISC      Toggle promiscuous mode.
  12736.  
  12737.  
  12738.    AmiTCP/IP EXTENSIONS
  12739.         Thefollowing ioctls are used to configure protocol and hardware
  12740.         specific properties of a sana_softc interface. They are used in the
  12741.         AmiTCP/IP only.
  12742.  
  12743.  
  12744.         SIOCSSANATAGS     Set SANA-II specific properties with a tag list.
  12745.  
  12746.  
  12747.         SIOCGSANATAGS     Get SANA-II specific properties into a
  12748.                           wiretype_parameters structure and a user tag list.
  12749.  
  12750.  
  12751.         struct  wiretype_parameters
  12752.         -
  12753.           ULONG  wiretype;                /* the wiretype of theinterface */
  12754.           WORD   flags;                                         /* iff_flags*/
  12755.           struct TagItem*tags;                   /* tag list userprovides */
  12756.  
  12757.  
  12758. 192    Section D.1                 AmiTCP/IP                  System Manual
  12759.  
  12760.  
  12761.  
  12762.         ";
  12763.  
  12764.  
  12765.    SEE ALSO
  12766.         arp, lo, netutil/arp, netutil/ifconfig, <sys/ioctl.h>, <net/if.h>,
  12767.         <net/sana2tags.h>
  12768.  
  12769.  
  12770. System Manual                  AmiTCP/IP                 Section D.1    193
  12771.  
  12772.  
  12773.  
  12774. D.1.4   inet
  12775.  
  12776.  
  12777.    NAME
  12778.         inet - Internet protocol family
  12779.  
  12780.  
  12781.    SYNOPSIS
  12782.         #include <sys/types.h>
  12783.         #include <netinet/in.h>
  12784.  
  12785.  
  12786.    DESCRIPTION
  12787.         TheInternet protocol family implements a collection of protocols
  12788.         which are centered around the Internet Protocol (IP) and which share
  12789.         a common address format.  The Internet family provides protocol
  12790.         support for the SOCK_STREAM, SOCK_DGRAM, and SOCK_RAW socket types.
  12791.  
  12792.  
  12793.    PROTOCOLS
  12794.         TheInternet protocol family is comprised of the Internet Protocol
  12795.         (IP), the Address Resolution Protocol (ARP), the Internet Control
  12796.         Message Protocol (ICMP), the Transmission Control Protocol (TCP),
  12797.         andthe User Datagram Protocol (UDP).
  12798.  
  12799.  
  12800.         TCPis used to support the SOCK_STREAM abstraction while UDP is used
  12801.         tosupport the SOCK_DGRAM abstraction; (SEE ALSO tcp, SEE ALSO udp).
  12802.         A raw interface to IP is available by creating an Internet socket of
  12803.         type SOCK_RAW; (SEE ALSO ip).  ICMP is used by the kernel to handle
  12804.         andreport errors in protocol processing.  It is also accessible to
  12805.         user programs; (SEE ALSO icmp).  ARP is used to translate 32-bit IP
  12806.         addresses into varying length hardware addresses; (SEE ALSO arp).
  12807.  
  12808.  
  12809.         The32-bit IP address is divided into network number and host number
  12810.         parts.   It is frequency-encoded; the most significant bit is zero in
  12811.         Class A addresses, in which the high-order 8 bits are the network
  12812.         number.   Class Baddresses have their high order two bits set to 10
  12813.         anduse the highorder 16 bits as the network number field.  Class C
  12814.         addresses have a 24-bit network number part of which the high order
  12815.         three bits are 110.  Sites with a cluster of local networks may
  12816.         chose to use a single network number for the cluster; this is done
  12817.         byusing subnet addressing.  The local (host) portion of the address
  12818.         isfurther subdivided into subnet number and host number parts.
  12819.         Within a subnet, each subnet appears to be an individual network;
  12820.         externally, the entire cluster appears to be a single, uniform
  12821.         network requiring only a single routing entry.  Subnet addressing is
  12822.         enabled and examined by the following ioctl commands on a datagram
  12823.         socket in the Internet domain; they have the same form as the
  12824.         SIOCIFADDR (SEE ALSO if) command.
  12825.  
  12826.  
  12827.         SIOCSIFNETMASK       Set interface network mask.   The network mask
  12828.                              defines the network part of the address; ifit
  12829.                              contains more of the address than the address
  12830.                              type would indicate, then subnets are in use.
  12831.  
  12832.  
  12833.         SIOCGIFNETMASK       Get interface network mask.
  12834.  
  12835.  
  12836.    ADDRESSING
  12837.         IPaddresses are four byte quantities, stored in network byte order
  12838.         (the native Amiga byte order)
  12839.  
  12840.  
  12841. 194    Section D.1                 AmiTCP/IP                  System Manual
  12842.  
  12843.  
  12844.  
  12845.         Sockets in the Internet protocol family  use  the  following
  12846.         addressing structure:
  12847.              struct sockaddr_in -
  12848.                   short      sin_family;
  12849.                   u_short   sin_port;
  12850.                   struct     in_addr sin_addr;
  12851.                   char sin_zero[8];
  12852.              ";
  12853.  
  12854.  
  12855.         Functions in bsdsocket.library are provided to manipulate structures
  12856.         ofthis form.
  12857.  
  12858.  
  12859.         Thesin_addr field of the sockaddr_in structure specifies a local or
  12860.         remote IP address.  Each network interface has its own unique IP
  12861.         address.   The special value INADDR_ANY may be used in this field to
  12862.         effect "wildcard" matching.  Given in a bind() call, this value
  12863.         leaves the local IP address of the socket unspecified, so that the
  12864.         socket will receive connections or messages directed at any of the
  12865.         valid IP addresses of the system.  This can prove useful when a
  12866.         process neither knows nor cares what the local IP address is or when
  12867.         a process wishes to receive requests using all of its network
  12868.         interfaces.   Thesockaddr_in structure given in the bind() call must
  12869.         specify an in_addr value of either IPADDR_ANY or one of the system's
  12870.         valid IP addresses.  Requests to bind any other address will elicit
  12871.         theerror EADDRNOTAVAIL. When a connect() call is made for a socket
  12872.         that has a wildcard local address, the system sets the sin_addr
  12873.         field of the socket to the IP address of the network interface that
  12874.         thepackets for that connection are routed via.
  12875.  
  12876.  
  12877.         Thesin_port field of the sockaddr_in structure specifies a port
  12878.         number used by TCP or UDP. The local port address specified in a
  12879.         bind() call is restricted to be greater than IPPORT_RESERVED
  12880.         (defined in <netinet/in.h>) unless the creating process is running
  12881.         asthe super-user, providing a space of protected port numbers.  In
  12882.         addition, the local port address must not be in use by any socket of
  12883.         same address family and type.  Requests to bind sockets to port
  12884.         numbers being used by other sockets return the error EADDRINUSE.  If
  12885.         thelocal port address is specified as 0, then the system picks a
  12886.         unique port address greater than IPPORT_RESERVED.  A unique local
  12887.         port address is also picked when a socket which is not bound is used
  12888.         ina connect() or send() call.  This allows programs which do not
  12889.         care which local port number is used to set up TCP connections by
  12890.         sim- ply calling socket() and then connect(), and to send UDP
  12891.         datagrams with a socket() call followed by a send() call.
  12892.  
  12893.  
  12894.         Although this implementation restricts sockets to unique local port
  12895.         numbers, TCP allows multiple simultaneous connections involving the
  12896.         same local port number so long as the remote IP addresses or port
  12897.         numbers are different for each connection.  Programs may explicitly
  12898.         override the socket restriction by setting the SO_REUSEADDR socket
  12899.         option with setsockopt (see getsockopt()).
  12900.  
  12901.  
  12902.    SEE ALSO
  12903.         bsdsocket.library/bind(), bsdsocket.library/connect(),
  12904.  
  12905.  
  12906. System Manual                  AmiTCP/IP                 Section D.1    195
  12907.  
  12908.  
  12909.  
  12910.         bsdsocket.library/getsockopt(), bsdsocket.library/IoctlSocket(),
  12911.         bsdsocket.library/send(), bsdsocket.library/socket(),
  12912.         bsdsocket.library/gethostent(), bsdsocket.library/getnetent(),
  12913.         bsdsocket.library/getprotoent(), bsdsocket.library/getservent(),
  12914.         bsdsocket.library/inet_addr(), arp, icmp, ip, tcp, udp
  12915.  
  12916.  
  12917.         Network Information Center, DDN Protocol Handbook (3 vols.),
  12918.         Network  Information  Center, SRI International, Menlo Park,
  12919.         Calif.,  1985.
  12920.         A AmiTCP/IP Interprocess Communication Primer
  12921.  
  12922.  
  12923.    WARNING
  12924.         TheInternet protocol support is subject to change as the Internet
  12925.         protocols develop.  Users should not depend on details of the
  12926.         current implementation, but rather the services exported.
  12927.  
  12928.  
  12929. 196    Section D.1                 AmiTCP/IP                  System Manual
  12930.  
  12931.  
  12932.  
  12933. D.1.5   ip
  12934.  
  12935.  
  12936.    NAME
  12937.         ip- Internet Protocol
  12938.  
  12939.  
  12940.    SYNOPSIS
  12941.         #include <sys/socket.h>
  12942.         #include <netinet/in.h>
  12943.  
  12944.  
  12945.         int
  12946.         socket(AF_INET, SOCK_RAW, proto)
  12947.  
  12948.  
  12949.    DESCRIPTION
  12950.         IPis the transport layer protocol used by the Internet protocol
  12951.         family.   Optionsmay be set at the IP level when using higher-level
  12952.         protocols that are based on IP (such as TCP and UDP). It may also be
  12953.         accessed through a ``raw socket'' when developing new protocols, or
  12954.         special purpose applica- tions.
  12955.  
  12956.  
  12957.         A single generic option is supported at the IP level, IP_OPTIONS,
  12958.         that may be used to provide IP options to be transmitted in the IP
  12959.         header of each outgoing packet.  Options are set with setsockopt()
  12960.         andexamined with getsockopt().  The format of IP options to be sent
  12961.         isthat specified by the IP protocol specification, with one
  12962.         exception: the list of addresses for Source Route options must
  12963.         include the first-hop gateway at the beginning of the list of
  12964.         gateways.   The first-hop gateway address will be extracted from the
  12965.         option list and the size adjusted accordingly before use.  IP
  12966.         options may be used with any socket type in the Internet family.
  12967.  
  12968.  
  12969.         RawIP sockets are connectionless, and are normally used with the
  12970.         sendto and recvfrom calls, though the connect() call may also be
  12971.         used to fix the destination for future packets (in which case the
  12972.         recv() and send() system calls may be used).
  12973.  
  12974.  
  12975.         Ifproto is 0, the default protocol IPPROTO_RAW is used for outgoing
  12976.         packets, and only incoming packets destined for that protocol are
  12977.         received.   If proto is non-zero, that protocol number will be used
  12978.         onoutgoing packets and to filter incoming packets.
  12979.  
  12980.  
  12981.         Outgoing packets automatically have an IP header prepended to them
  12982.         (based on the destination address and the protocol number the socket
  12983.         iscreated with).  Incoming packets are received with IP header and
  12984.         options  intact.
  12985.  
  12986.  
  12987.    DIAGNOSTICS
  12988.         A socket operation may fail with one of the following errors
  12989.         returned:
  12990.  
  12991.  
  12992.         [EISCONN]         when trying to establish a connection ona socket
  12993.                           which already has one, orwhen trying to send a
  12994.                           datagram with the destination address specified and
  12995.                           the socket is already connected;
  12996.  
  12997.  
  12998.         [ENOTCONN]        when trying tosend a datagram, but no destination
  12999.                           address is specified, andthe socket hasn't been
  13000.  
  13001.  
  13002. System Manual                  AmiTCP/IP                 Section D.1    197
  13003.  
  13004.  
  13005.  
  13006.                           connected;
  13007.  
  13008.  
  13009.         [ENOBUFS]         when the system runs out of memory for aninternal
  13010.                           data structure;
  13011.  
  13012.  
  13013.         [EADDRNOTAVAIL]  when an attempt is made to create a socket with a
  13014.                           network address for whichno network interface
  13015.                           exists.
  13016.  
  13017.  
  13018.         Thefollowing errors specific to IP may occur when setting or
  13019.         getting IP options:
  13020.  
  13021.  
  13022.         [EINVAL]          An unknown socket option name was given.
  13023.  
  13024.  
  13025.         [EINVAL]          The IP option field was improperly formed; an
  13026.                           option field was shorterthan the minimum value or
  13027.                           longer than the option buffer provided.
  13028.  
  13029.  
  13030.    SEE ALSO
  13031.         bsdsocket.library/getsockopt(), bsdsocket.library/send(),
  13032.         bsdsocket.library/recv(), icmp, inet
  13033.  
  13034.  
  13035.    HISTORY
  13036.         Theip protocol appeared in 4.2BSD.
  13037.  
  13038.  
  13039. 198    Section D.1                 AmiTCP/IP                  System Manual
  13040.  
  13041.  
  13042.  
  13043. D.1.6   lo
  13044.  
  13045.    NAME
  13046.         lo- Software Loopback Network Interface
  13047.  
  13048.  
  13049.    SYNOPSIS
  13050.         pseudo-device
  13051.         loop
  13052.  
  13053.  
  13054.    DESCRIPTION
  13055.         Theloop interface is a software loopback mechanism which may be
  13056.         used for performance analysis, software testing, and/or local
  13057.         communication.  There is no SANA-II interface associated with lo.
  13058.         Aswith other network interfaces, the loopback interface must have
  13059.         network addresses assigned for each address family with which it is
  13060.         tobe used.   These addresses may be set or changed with the
  13061.         SIOCSIFADDR ioctl. The loopback interface should be the last
  13062.         interface configured, as protocols may use the order of
  13063.         configuration as an indication of priority.  The loopback should
  13064.         never be configured first unless no hardware interfaces exist.
  13065.  
  13066.  
  13067.    DIAGNOSTICS
  13068.         "lo%d: can't handle af%d."
  13069.         Theinterface was handed a message with ad- dresses formatted in an
  13070.         unsuitable address family; the packet was dropped.
  13071.  
  13072.  
  13073.    SEE ALSO
  13074.         inet, if, netutil/ifconfig
  13075.  
  13076.  
  13077.    BUGS
  13078.         Older BSD Unix systems enabled the loopback interface
  13079.         automatically, using a nonstandard Internet address (127.1).  Use
  13080.         ofthat address is now discouraged; a reserved host address for the
  13081.         local network should be used instead.
  13082.  
  13083.  
  13084. System Manual                  AmiTCP/IP                 Section D.1    199
  13085.  
  13086.  
  13087.  
  13088. D.1.7   routing
  13089.  
  13090.  
  13091.    NAME
  13092.         routing - system supporting for local network packet routing
  13093.  
  13094.  
  13095.    DESCRIPTION
  13096.         Thenetwork facilities provided general packet routing,
  13097.         leaving routing table maintenance to applications processes.
  13098.  
  13099.  
  13100.         A simple set of data structures comprise a ``routing table''
  13101.         used in selecting the appropriate network interface when
  13102.         transmitting packets.  This table contains a single entry for
  13103.         each route to a specific network or host.  A user process, the
  13104.         routing daemon, maintains this data base with the aid of two
  13105.         socket specific ioctl commands, SIOCADDRT and SIOCDELRT.
  13106.         Thecommands allow the addition and deletion of a single
  13107.         routing table entry, respectively.  Routing table
  13108.         manipulations may only be carried out by super-user.
  13109.  
  13110.  
  13111.         A routing table entry has the following form, as defined  in
  13112.         <net/route.h>:
  13113.              struct rtentry -
  13114.                   u_long     rt_hash;
  13115.                   struct     sockaddr rt_dst;
  13116.                   struct     sockaddr rt_gateway;
  13117.                   short      rt_flags;
  13118.                   short      rt_refcnt;
  13119.                   u_long     rt_use;
  13120.                   struct     ifnet  *rt_ifp;
  13121.              ";
  13122.         with rt_flags defined from:
  13123.           #define   RTF_UP          0x1               /* route usable */
  13124.           #define   RTF_GATEWAY    0x2  /* destination is a gateway */
  13125.           #define   RTF_HOST  0x4     /* host entry (net otherwise) */
  13126.  
  13127.  
  13128.         Routing table entries come in three flavors: for a specific
  13129.         host, for all hosts on a specific network, for any destination
  13130.         notmatched by entries of the first two types (a wildcard
  13131.         route).   When the system is booted, each network interface
  13132.         autoconfigured installs a routing table entry when it wishes
  13133.         tohave packets sent through it.  Normally the interface
  13134.         specifies the route through it is a ``direct'' connection to
  13135.         thedestination host or network.  If the route is direct, the
  13136.         transport layer of a protocol family usually requests the
  13137.         packet be sent to the same host specified in the packet.
  13138.         Otherwise, the interface may be requested to address the
  13139.         packet to an entity different from the eventual recipient
  13140.         (that is, the packet is forwarded).
  13141.  
  13142.  
  13143.         Routing table entries installed by a user process may not
  13144.         specify the hash, reference count, use, or interface fields;
  13145.         these are filled in by the routing routines.  If a route is in
  13146.         usewhen it is deleted (rt_refcnt is non-zero), the resources
  13147.         associated with it will not be reclaimed until all references
  13148.         toit are removed.
  13149.  
  13150.  
  13151. 200    Section D.1                 AmiTCP/IP                  System Manual
  13152.  
  13153.  
  13154.  
  13155.         Therouting code returns EEXIST if requested to duplicate an
  13156.         existing entry, ESRCH if requested to delete a non-existent
  13157.         entry, or ENOBUFS if insufficient resources were available to
  13158.         install a new route.
  13159.  
  13160.  
  13161.         Thert_use field contains the number of packets sent along the
  13162.         route.   This value is used to select among multiple routes to
  13163.         thesame destination.  When multiple routes to the same
  13164.         destination exist, the least used route is selected.
  13165.  
  13166.  
  13167.         A wildcard routing entry is specified with a zero destination
  13168.         address value.  Wildcard routes are used only when the system
  13169.         fails to find a route to the destination host and network.
  13170.         Thecombination of wildcard routes and routing redirects can
  13171.         provide an economical mechanism for routing traffic.
  13172.  
  13173.  
  13174.    SEE ALSO
  13175.         bsdsocket.library/IoctlSocket(), netutil/route
  13176.  
  13177.  
  13178. System Manual                  AmiTCP/IP                 Section D.1    201
  13179.  
  13180.  
  13181.  
  13182. D.1.8   tcp
  13183.  
  13184.  
  13185.    NAME
  13186.         tcp- Internet Transmission Control Protocol
  13187.  
  13188.  
  13189.    SYNOPSIS
  13190.         #include <sys/socket.h>
  13191.         #include <netinet/in.h>
  13192.  
  13193.  
  13194.         int
  13195.         socket(AF_INET, SOCK_STREAM, 0)
  13196.  
  13197.  
  13198.    DESCRIPTION
  13199.         TheTCP protocol provides reliable, flow-controlled, two-way
  13200.         transmission of data.  It is a byte-stream protocol used to support
  13201.         theSOCK_STREAM abstraction.  TCP uses the standard Internet address
  13202.         format and, in addition, provides a per-host collection of ``port
  13203.         addresses''. Thus, each address is composed of an Internet address
  13204.         specifying the host and network, with a specific TCP port on the
  13205.         host identifying the peer entity.
  13206.  
  13207.  
  13208.         Sockets utilizing the tcp protocol are either ``active'' or
  13209.         ``passive''.   Active sockets initiate connections to passive
  13210.         sockets.   By default TCP sockets are created active; to create a
  13211.         passive socket the listen() bsdsocket.library function call must be
  13212.         used after binding the socket with the bind() bsdsocket.library
  13213.         function call.  Only passive sockets may use the accept() call to
  13214.         accept incoming connections.  Only active sockets may use the
  13215.         connect() call to initiate connections.
  13216.  
  13217.  
  13218.         Passive sockets may ``underspecify'' their location to match
  13219.         incoming connection requests from multiple networks.  This
  13220.         technique, termed ``wildcard addressing'', allows a single server to
  13221.         provide service to clients on multiple networks.  To create a socket
  13222.         which listens on all networks, the Internet address INADDR_ANY must
  13223.         bebound.   The TCP port may still be specified at this time; if the
  13224.         port is not specified the bsdsocket.library function will assign
  13225.         one.   Once a connection has been established the socket's address is
  13226.         fixed by the peer entity's location.  The address assigned the
  13227.         socket is the address associated with the network interface through
  13228.         which packets are being transmitted and received.  Normally this
  13229.         address corresponds to the peer entity's network.
  13230.  
  13231.  
  13232.         TCPsupports one socket option which is set with setsockopt() and
  13233.         tested with getsockopt().  Under most circumstances, TCP sends data
  13234.         when it is presented; when outstanding data has not yet been
  13235.         acknowledged, it gathers small amounts of output to be sent in a
  13236.         single packet once an acknowledgement is received.  For a small
  13237.         number of clients, such as X Window System functions that
  13238.         send a stream of mouse events which receive no replies, this
  13239.         packetization may cause significant delays.  Therefore, TCP provides
  13240.         a boolean option, TCP_NODELAY (from <netinet/tcp.h>, to defeat this
  13241.         algorithm.   Theoption level for the setsockopt call is the protocol
  13242.         number for TCP, available from getprotobyname().
  13243.  
  13244.  
  13245.         Options at the IP transport level may be used with TCP; SEE ALSO ip.
  13246.  
  13247.  
  13248. 202    Section D.1                 AmiTCP/IP                  System Manual
  13249.  
  13250.  
  13251.  
  13252.         Incoming connection requests that are source-routed are noted, and
  13253.         thereverse source route is used in responding.
  13254.  
  13255.  
  13256.    DIAGNOSTICS
  13257.         A socket operation may fail with one of the following errors
  13258.         returned:
  13259.  
  13260.  
  13261.         [EISCONN]         when trying to establish a connection ona socket
  13262.                           which already has one;
  13263.  
  13264.  
  13265.         [ENOBUFS]         when the AmiTCP/IP runs out of memory foran internal
  13266.                           data structure;
  13267.  
  13268.  
  13269.         [ETIMEDOUT]       when a connection was dropped due to excessive
  13270.                           retransmissions;
  13271.  
  13272.  
  13273.         [ECONNRESET]      when the remote peerforces the connection to be
  13274.                           closed;
  13275.  
  13276.  
  13277.         [ECONNREFUSED]    when the remote peer actively refuses connection
  13278.                           establishment (usually because no process is
  13279.                           listening to the port);
  13280.  
  13281.  
  13282.         [EADDRINUSE]      when an attempt is made to create a socket with a
  13283.                           port which has already been allocated;
  13284.  
  13285.  
  13286.         [EADDRNOTAVAIL]  when an attempt is made to create a socket with a
  13287.                           network address for whichno network interface
  13288.                           exists.
  13289.  
  13290.  
  13291.    SEE ALSO
  13292.         bsdsocket.library/getsockopt(), bsdsocket.library/socket(),
  13293.         bsdsocket.library/bind(), bsdsocket.library/listen(),
  13294.         bsdsocket.library/accept(), bsdsocket.library/connect(), inet,
  13295.         ip,<sys/socket.h>, <netinet/tcp.h>, <netinet/in.h>
  13296.  
  13297.  
  13298.    HISTORY
  13299.         Thetcp protocol stack appeared in 4.2BSD.
  13300.  
  13301.  
  13302. System Manual                  AmiTCP/IP                 Section D.1    203
  13303.  
  13304.  
  13305.  
  13306. D.1.9   udp
  13307.  
  13308.  
  13309.    NAME
  13310.         udp- Internet User Datagram Protocol
  13311.  
  13312.  
  13313.    SYNOPSIS
  13314.         #include <sys/socket.h>
  13315.         #include <netinet/in.h>
  13316.  
  13317.  
  13318.         int
  13319.         socket(AF_INET, SOCK_DGRAM, 0)
  13320.  
  13321.  
  13322.    DESCRIPTION
  13323.         UDPis a simple, unreliable datagram protocol which is used to
  13324.         support the SOCK_DGRAM abstraction for the Internet protocol family.
  13325.         UDPsockets are connectionless, and are normally used with the
  13326.         sendto() and recvfrom() calls, though the connect() call may also be
  13327.         used to fix the destination for future packets (in which case the
  13328.         recv() and send() function calls may be used).
  13329.  
  13330.  
  13331.         UDPaddress formats are identical to those used by TCP. In
  13332.         particular UDP provides a port identifier in addition to the normal
  13333.         Internet address format.  Note that the UDP port space is separate
  13334.         from the TCP port space (i.e. a UDP port may not be ``connected'' to
  13335.         a TCP port). In addition broadcast packets may be sent (assuming the
  13336.         underlying network supports this) by using a reserved ``broadcast
  13337.         address''; this address is network interface dependent.
  13338.  
  13339.  
  13340.         Options at the IP transport level may be used with UDP; SEE ALSO ip.
  13341.  
  13342.  
  13343.    DIAGNOSTICS
  13344.         A socket operation may fail with one of the following errors
  13345.         returned:
  13346.  
  13347.  
  13348.         [EISCONN]         when trying to establish a connection ona socket
  13349.                           which already has one, orwhen trying to send a
  13350.                           datagram with the destination address specified and
  13351.                           the socket is already connected;
  13352.  
  13353.  
  13354.         [ENOTCONN]        when trying tosend a datagram, but no destination
  13355.                           address is specified, andthe socket hasn't been
  13356.                           connected;
  13357.  
  13358.  
  13359.         [ENOBUFS]         when the system runs out of memory for an
  13360.                           internal data structure;
  13361.  
  13362.  
  13363.         [EADDRINUSE]      when an attempt is made to create a socket with a
  13364.                           port which has already been allocated;
  13365.  
  13366.  
  13367.         [EADDRNOTAVAIL]  when an attempt is made to create a socket with a
  13368.                           network address for whichno network interface
  13369.                           exists.
  13370.  
  13371.  
  13372.    SEE ALSO
  13373.         bsdsocket.library/getsockopt(), bsdsocket.library/recv(),
  13374.         bsdsocket.library/send(), bsdsocket.library/socket(), inet, ip
  13375.  
  13376.  
  13377. 204    Section D.1                 AmiTCP/IP                  System Manual
  13378.  
  13379.  
  13380.  
  13381.    HISTORY
  13382.         Theudp protocol appeared in 4.2BSD.
  13383.  
  13384.  
  13385.  
  13386.  
  13387.  
  13388. Glossary
  13389.  
  13390.  
  13391.  
  13392. API Application Program Interface.  Standard function calls, messages and
  13393.     devices used in application level programs.
  13394.  
  13395.  
  13396. Arcnet Yet another network type, transfer rate 5Mbits/sec.
  13397.  
  13398.  
  13399. ARexx ARexx is a specific implementation of the Rexx language forthe
  13400.     Amiga.  Rexx itself is a script language with superb power/simplicity
  13401.     ratio, originally developed for some IBM mainframe systems.
  13402.  
  13403.  
  13404. ARP Address Resolution Protocol.  A communication protocol used tomap
  13405.     protocol address to network address dynamically.  For example, ARP is
  13406.     used to map DARPA Internet addresses into Ethernet addresses.
  13407.  
  13408.  
  13409. AutoDoc Document generated automagically from comments included in
  13410.     program source code.  Mainly used to describe shared library
  13411.     functions in AmigaOS. See [RKM Inc & ADoc 1992 ].
  13412.  
  13413.  
  13414. BSD Berkeley Software Distribution.  Family of UNIX versions for the DEC
  13415.     (VAX) and PDP-11 developed by Bill Joy and others at Berzerkeley
  13416.     starting around 1980, incorporating paged virtual memory, TCP/IP
  13417.     networking enhancements, and many other features.  The BSD versions
  13418.     (4.1, 4.2, and 4.3) and the commercial versions derived from them
  13419.     (SunOS, ULTRIX, and Mt.  Xinu) held the technical lead in the UNIX
  13420.     world until AT&T's successful standardization efforts after about
  13421.     1986, and are still widely popular.
  13422.  
  13423.  
  13424. BSDSS BSD Single Server is operating system server in Mach operating
  13425.     system where all UNIX services are in single binary.
  13426.  
  13427.  
  13428. (D)ARPA Internet  The collection of networks using internet protocols.
  13429.     (D)ARPA Internet originated from a research project sponsored by the
  13430.     (Defense) Advanced Research Project Agency.
  13431.  
  13432.  
  13433. Daemon 'A deified being', program that lives forever on system, or
  13434.     reincarnates every time it is needed.  Performs its requested task
  13435.     promptly and goes back to sleep.
  13436.  
  13437.  
  13438. Data link layer  Protocol layer providing data transfer between machines
  13439.     in same physical network.
  13440.  
  13441.  
  13442. DIS First stage in ISO's standardization.  (Discussion)
  13443.  
  13444.  
  13445.  
  13446.                                       205
  13447.  
  13448.  
  13449. 206    Section D.1                 AmiTCP/IP                  System Manual
  13450.  
  13451.  
  13452.  
  13453. Ethernet 10Mbit/sec physical network interface.  Developed by Xerox in
  13454.     Palo Alto late 70s.  In 1982 published with Digital and Intel as
  13455.     ESPEC1.  ESPEC2 was approved as basic specification for LANs which
  13456.     employed the carrier sense multiple access with collision detection
  13457.     by IEEE 802.3 committee.  Heavily derived version was later published
  13458.     by ISO as DIS 8802/3.  Original has only version for 50  coaxial
  13459.     cable, 10BASE5 ``Thick Ether'', but nowadays has also for thinner
  13460.     coaxial cable, 10BASE2 ``Thin Ether'', twisted pair, 10BASET and
  13461.     fibre, 10BASEF. There are also broadband, 10BROAD36, and slower,
  13462.     1Mbit/s 1BASE5, versions.
  13463.  
  13464.  
  13465. EXEC AmigaOS EXECutive.  Provides the basic kernel functions, such as
  13466.     task scheduling, memory management, concurrency control, message
  13467.     ports, public library lists etc.
  13468.  
  13469.  
  13470. Frame Data unit transferred between data link layer protocol entities.
  13471.  
  13472.  
  13473. ICMP Internet Message Control Protocol.  A host-to-host communication
  13474.     protocol used in the DARPA Internet for reporting errors and
  13475.     controlling the operation of IP.
  13476.  
  13477.  
  13478. IEEE the Institute of Electrical and Electronics Engineers
  13479.  
  13480.  
  13481. Inetd the Internet super server.  A server that listens to the network
  13482.     and launches other server processes when needed.
  13483.  
  13484.  
  13485. IO request  An Amiga standard message format to discuss with devices.  IO
  13486.     requests are sent by Exec function BeginIO() to the device driver.
  13487.     Completed IO requests are sent back to the reply port specified in IO
  13488.     request.
  13489.  
  13490.  
  13491. IP Internet Protocol.  The network-layer communication protocol used in
  13492.     the DARPA Internet.  IP is responsible for host-to-host addressing
  13493.     and routing, packet forwarding, and packet fragmentation and
  13494.     reassembly.
  13495.  
  13496.  
  13497. ISO International Organization for Standardization
  13498.  
  13499.  
  13500. Jargon A formal technical vocabulary of various subjects.  Also hackish
  13501.     slang or mumbo jumbo is referred as jargon [Raymond 1992 ].
  13502.  
  13503.  
  13504. Library base  In AmigaOS shared library is accessed via a library base
  13505.     pointer.  On the negative side (relative to the base pointer) there
  13506.     is jump table to the library functions and on the positive side --
  13507.     library data the functions can use.
  13508.  
  13509.  
  13510. Log It is usually useful to record information.  If something hasgone
  13511.     wrong, one may found information to remove cause of failure.  A log
  13512.     is usually a file, where information is written.
  13513.  
  13514.  
  13515. Mbuf Memory BUFfer.  Data storage unit inside BSD networking
  13516.     implementation.
  13517.  
  13518.  
  13519. Message Data unit transferred between applications using network
  13520.     services.
  13521.  
  13522.  
  13523. System Manual                  AmiTCP/IP                 Section D.1    207
  13524.  
  13525.  
  13526.  
  13527. MTU Maximum Transfer Unit.  The amount of data that underlying network
  13528.     can transfer in one block.
  13529.  
  13530. NET/2 Latest (by now) BSD Unix release.
  13531.  
  13532. Network File System  A filesystem share protocol which enables other
  13533.     computers use disks on other host over network.  Usually uses UDP
  13534.     protocol for transfering files, but also TCP-based version exists.
  13535.     Developed by Sun Microsystems Inc., and developed to ``Industrial
  13536.     Standard'' in *IX environment.  Described in detail ``Networking on
  13537.     the Sun Workstation''
  13538.  
  13539. Octet A unit of eigth bits.  Used in communication to overcome problem
  13540.     that byte is not allways eigth bits (althoug this is nowadays very
  13541.     rare situation.)
  13542.  
  13543. Packet Data unit transferred between network layer protocol entities.
  13544.  
  13545. panic() Function executed after lethal failure in Unix kernel.
  13546.  
  13547. PPP Point-to-Point Protocol which allows multiple protocols to be
  13548.     transferred on the same line.  It is also more flexible than SLIP.
  13549.  
  13550. Protocol stack  A network protocol stack is a layerof software that
  13551.     network applications use to address particular processes on remote
  13552.     machines.  The AmiTCP/IP is such a protocol stack using TCP/IP
  13553.     protocols.
  13554.  
  13555. RARP Reverse Address Resolution Protocol maps network addresses to
  13556.     protocol addresses dynamically.
  13557.  
  13558. RFC Request For Comments.  Freely available standards for networking.
  13559.     They are mostly available online from nic.ddn.mil with FTP or Kermit.
  13560.  
  13561. RKM Rom Kernel reference Manuals are the most authoritative AmigaOS
  13562.     references, see [RKM Libraries 1992 ] for example.
  13563.  
  13564. SANA-II A standard for an Amiga software interface between networking
  13565.     hardware and network protocol stacks (or for software tools such as
  13566.     network monitors).
  13567.  
  13568. SLIP Serial Line Internet Protocol.  Data encapsulation protocol used to
  13569.     transmit IP packets over point-to-point serial lines.
  13570.  
  13571. Socket An abstraction for endpoint of communication.
  13572.  
  13573. TLA Three Letter Acronym, a mnemonic and mystic abbreviation which is
  13574.     coined to confuse acolytes.
  13575.  
  13576. TCP Transmission Control Protocol.  A connection-oriented transport
  13577.     protocol used in the DARPA Internet.  TCP provides for the reliable
  13578.     transfer of data, as well as the out-of-band indication of urgent
  13579.     data.
  13580.  
  13581. TCP/IP The whole protocol stack, which implements at least the Internet
  13582.     protocols required is often expressed as the two most commonly used,
  13583.     TCP/IP
  13584.  
  13585.  
  13586. 208    Section D.1                 AmiTCP/IP                  System Manual
  13587.  
  13588.  
  13589.  
  13590. UDP User Datagram Protocol.  A simple unreliable datagram protocolused
  13591.     in the DARPA Internet.  UDP provides only peer-to-peer addressing and
  13592.     optional data checksum.
  13593.  
  13594. Wire type  is the physical layer protocol type.  Different wire types are
  13595.     for instance Arcnet, Ethernet, IEEE 802.3, PPP and SLIP.
  13596.  
  13597.  
  13598.  
  13599.  
  13600.  
  13601. Bibliography
  13602.  
  13603.  
  13604.  
  13605. [Comer 1988]               Comer, D. E., Internetworking With TCP/IP Vol I:
  13606.                            Principles, Protocols and Architecture,
  13607.                            Prentice--HallInternational, 382 p.
  13608.  
  13609.  
  13610. [Comer and Stevens 1991]   Comer, D. E. and Stevens, D. L., Internetworking
  13611.                            With TCP/IP VolII: Design, Implementation, and
  13612.                            Internals, Prentice--Hall International, 524 p.
  13613.  
  13614.  
  13615. [Finlayson et al 1984]     Finlayson, R.,Mann, T., Mogul, J. and Theimer,
  13616.                            M., ``A ReverseAddress Resolution Protocol,''
  13617.                            RFC 903, 4 p.
  13618.  
  13619.  
  13620. [Holloway 1991]            Holloway, T., ``Object Oriented Amiga EXEC,''
  13621.                            BYTE, vol. 16,issue 1, pp. 329--334, January
  13622.                            1991.
  13623.  
  13624.  
  13625. [Jacobson 1990]            Jacobson, V., ``Compressing TCP/IP Headers for
  13626.                            Low-speed Serial Links,'' RFC 1144, 43 p.
  13627.  
  13628.  
  13629. [Leffler et al 1989]       Leffler, S. J.,McKusick, M. K., Karels, M. J.
  13630.                            and Quarterman,J. S., The Design and
  13631.                            Implementationof the 4.3BSD UNIX Operating
  13632.                            System, Addison--Wesley 471 p.
  13633.  
  13634.  
  13635. [Leffler et al 1991a]      Leffler, S. J.,Fabry, R. S., Joy, W. N.,
  13636.                            Lapsley, P., Miller, S., Torek, C., ``An
  13637.                            Advanced 4.3BSDInterprocess Communication
  13638.                            Tutorial'' UNIXProgrammer's Supplementary
  13639.                            Documents (PS1), net/2 Berkeley Software
  13640.                            Distribution, Computer Systems Research Group,
  13641.                            Univ. of California, Berkeley, 53 p.
  13642.  
  13643.  
  13644. [Leffler et al 1991b]      Leffler, S. J.,Joy, W. N., Fabry, R. S. and
  13645.                            Karels, M. J.,``Networking Implementation
  13646.                            Notes, 4.3BSD Edition,'' UNIX System Manager's
  13647.                            Manual (SMM), net/2 Berkeley Software
  13648.                            Distribution, Computer Systems Research Group,
  13649.                            Computer Science Division, Univ. of California,
  13650.                            Berkeley, 26 p.
  13651.  
  13652.  
  13653. [Plummer 1982]             Plummer, D. C.,``An Ethernet Address Resolution
  13654.                            Protocol,'' RFC826, 10 p.
  13655.  
  13656.  
  13657.  
  13658.                                       209
  13659.  
  13660.  
  13661. 210    Section D.1                 AmiTCP/IP                  System Manual
  13662.  
  13663.  
  13664.  
  13665. [Postel 1980]              Postel, J., ``User Datagram Protocol,'' RFC 768,
  13666.                            3 p.
  13667.  
  13668. [Postel 1981a]             Postel, J. ed.,``Internet Protocol,'' RFC 791,
  13669.                            45 p.
  13670.  
  13671. [Postel 1981b]             Postel, J., ``Internet Control Message
  13672.                            Protocol,'' RFC792, 21 p.
  13673.  
  13674. [Postel 1981c]             Postel, J. ed.,``Transmission Control
  13675.                            Protocol,'' RFC793, 85 p.
  13676.  
  13677. [Raymond 1992]             Raymond, Eric ed., ``The Jargon File 2.9.9'',
  13678.                            the on-line hacker Jargon File, version 2.9.9,
  13679.                            01 APR 1992.
  13680.  
  13681. [Reynolds 1990]            Reynolds, JoyceK., ``Assigned Numbers'', RFC
  13682.                            1060, 86 p.
  13683.  
  13684. [RKM Libs & Devs 1989]     Commodore--Amiga Inc., Amiga ROM Kernel
  13685.                            Reference Manual:   Librariesand Devices,
  13686.                            Addison Wesley,956 p.
  13687.  
  13688. [RKM Libraries 1992]       Commodore--Amiga Inc., Amiga ROM Kernel
  13689.                            Reference Manual:   Libraries, 3rd ed., Addison
  13690.                            Wesley, 967 p.
  13691.  
  13692. [RKM Inc & ADoc 1992]      Commodore--Amiga Inc., Amiga ROM Kernel
  13693.                            Reference Manual:   Includes& AutoDocs, 3rd ed.,
  13694.                            Addison Wesley,471 p.
  13695.  
  13696. [SANA-II 1992]             Amiga Networking Group, ``SANA-II Network Device
  13697.                            Driver Specification - Rev 1.0 23-Apr-92,''
  13698.                            published at Fred Fish-collection disk#673.
  13699.  
  13700. [SANA-II 1992 add]         Amiga Networking Group, ``Addenda to SANA-II
  13701.                            Network DeviceDriver Specification,'' published
  13702.                            at SANA-II Developer Support Package, May 21,
  13703.                            1992.
  13704.  
  13705. [Stevens 1990]             Stevens, W., R., UNIX network programming,
  13706.                            Prentice Hall,772 p.
  13707.  
  13708. [Winsock 1992]             Hall, M., Towfiq, M., Arnold, G., Trendwell, D.,
  13709.                            Sanders, H., ``Windows Sockets An Open Interface
  13710.                            for Network Programming under Microsoft Windows
  13711.                            Version 1.0 Rev.A'' 11 June, 1992, 124 p.
  13712.  
  13713.  
  13714.    The RFC documents are stored online on nic.ddn.mil, from where they can
  13715. be downloaded with anonymous FTP. The file /rfc/rfc-index.txt contains
  13716. index to all published RFCs.
  13717.    The BSD documents are carried by many FTP sites, for example
  13718. nic.funet.fi.
  13719.